Pocketphinxで少しのVoiceRecognitionをプログラムしようとしました。PocketsphinxのJNIバインディングでのアクセス違反
まず、私はsphinxbaseとpocketsphinxを作りました。私はcmdからpocketsphinx_continuousを起動することができます。私はinmicモードでのみ使用したいです。
私はc-ソースを書き直そうとしましたので、私はinmic-modeしか持っていませんでした。私はこのコードから.dllを構築し、Eclipseで実行しようとしました。
これは私のJavaソース
public class Test {
private native Test Decoder_defaultConfig();
private native void recognize_from_mic();
public static void main(final String[] args) {
final Test test = new Test().Decoder_defaultConfig();
test.recognize_from_mic();
}
static {
System.loadLibrary("pocketsphinx_Test");
}
}
そして、生成されたヘッダー・ファイルです:私は、Javaを実行する場合
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <jni.h>
#include <sphinxbase\cmd_ln.h>
#include <windows.h>
#include <sphinxbase/err.h>
#include <sphinxbase/ad.h>
#include "pocketsphinx.h"
#define MODELDIR "C:/Users/310086414/Desktop/pocketsphinx/pocketsphinx/bin/Release/x64/model"
const char * recognize_from_microphone();
static ps_decoder_t *ps;
static cmd_ln_t *config;
static FILE *rawfd;
ad_rec_t *ad;
int16 adbuf[2048];
uint8 utt_started, in_speech;
int32 k;
char const *hyp;
char const *decoded_speech;
JNIEXPORT void JNICALL Java_Test_Decoder_1defaultConfig(JNIEnv *env, jobject obj)
{
config = cmd_ln_init(NULL, ps_args(), TRUE, // Load the configuration structure - ps_args() passes the default values
"-hmm", MODELDIR "/en-us/en-us", // path to the standard english language model
"-lm", MODELDIR "/en-us/en-us.lm.bin", // custom language model (file must be present)
"-dict", MODELDIR "/en-us/cmudict_en_us.dict", // custom dictionary (file must be present)
NULL);
if (config == NULL) {
cmd_ln_free_r(config);
E_INFO("configuration failed");
}
ps = ps_init(config); // initialize the pocketsphinx decoder
if (ps == NULL) {
cmd_ln_free_r(config);
E_INFO("decoder failed");
}
ad = ad_open_dev("sysdefault", (int)cmd_ln_float32_r(config, "-samprate")); // open default microphone at default samplerate
while (1) {
decoded_speech = recognize_from_microphone(); // call the function to capture and decode speech
printf("You Said: %s\n", decoded_speech); // send decoded speech to screen
}
ad_close(ad); // close the microphone
}
const char * recognize_from_microphone() {
ad_start_rec(ad); // start recording
ps_start_utt(ps); // mark the start of the utterance
utt_started = FALSE; // clear the utt_started flag
while (1) {
k = ad_read(ad, adbuf, 4096); // capture the number of frames in the audio buffer
ps_process_raw(ps, adbuf, k, FALSE, FALSE); // send the audio buffer to the pocketsphinx decoder
in_speech = ps_get_in_speech(ps); // test to see if speech is being detected
if (in_speech && !utt_started) { // if speech has started and utt_started flag is false
utt_started = TRUE; // then set the flag
}
if (!in_speech && utt_started) { // if speech has ended and the utt_started flag is true
ps_end_utt(ps); // then mark the end of the utterance
ad_stop_rec(ad); // stop recording
hyp = ps_get_hyp(ps, NULL); // query pocketsphinx for "hypothesis" of decoded statement
return hyp; // the function returns the hypothesis
break; // exit the while loop and return to main
}
}
}
:私は私のCソースを変更
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Test */
#ifndef _Included_Test
#define _Included_Test
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: Test
* Method: Decoder_defaultConfig
* Signature:()LTest;
*/
JNIEXPORT jobject JNICALL Java_Test_Decoder_1defaultConfig
(JNIEnv *, jobject);
/*
* Class: Test
* Method: recognize_from_mic
* Signature:()V
*/
JNIEXPORT void JNICALL Java_Test_recognize_1from_1mic
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
Eclipseで今すぐ次のメッセージが表示されます。
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000023bfbfc, pid=9780, tid=0x0000000000002a38
#
# JRE version: OpenJDK Runtime Environment (8.0_74-b02) (build 1.8.0_74-b02)
# Java VM: OpenJDK 64-Bit Server VM (25.74-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [pocketsphinx.dll+0x1fbfc] ps_start_utt+0x1c
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\sde\workspaceAW_4.5\pocketsphinx\hs_err_pid9780.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
ps_start_uttに問題はありますが、何も変更していないと言われています。 sphinaxbase/pocketsphinxの使用に間違いはありますか?
ありがとうございました!私はもう致命的なエラーを取得しません。 – PP600
しかし、inmicモードを設定するにはどうすればいいですか? – PP600
あなたのコードはデフォルトでマイクから認識されるため、インミミックモードは必要ありません。 'ps_init'でデコーダを初期化する前に、configオブジェクトの' cmd_ln_set_str_r'関数呼び出しでコード内にHMMパスを設定することができます –