2016-05-04 1 views
1

Je tente de programmer un peu VoiceRecognition avec Pocketsphinx.Violation d'accès dans les liaisons JNI pour Pocketsphinx

D'abord j'ai construit sphinxbase et pocketsphinx. Je suis capable de démarrer pocketsphinx_continuous sur cmd. Je veux l'utiliser uniquement en mode inmic.

Maintenant, j'ai essayé de réécrire la source c de sorte que je n'ai que le mode inmic. J'ai construit un fichier .dll à partir de ce code et j'ai essayé de l'exécuter dans Eclipse.

Ceci est mon Java Source

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"); 
    } 
} 

Et l'en-tête fichier généré:

/* 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 

J'ai changé mon c-source:

#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 
     } 
    } 

    } 

Si je lance Java -source maintenant avec Eclipse Je reçois le message suivant:

# 
# 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. 
# 

Il est dit qu'il y a un problème dans ps_start_utt, mais je n'ai rien changé. Y at-il encore une erreur dans l'utilisation de sphinaxbase/pocketsphinx?

Répondre

0

Cette partie

config = cmd_ln_init(NULL, ps_args(), "-inmic", "yes", TRUE, NULL); 

    if (config == NULL || cmd_ln_boolean_r(config, "-inmic") == FALSE) { 
     E_INFO("Specify '-inmic yes' to recognize from microphone.\n"); 
     cmd_ln_free_r(config); 

    } 

est-ce pas tout à fait correct. "-inmic" est une option de pocketsphinx_continuous, pas une option de sphinxbase. Il devrait être tout simplement

config = cmd_ln_init(NULL, ps_args(), TRUE, NULL); 

, vous devez également quitter le programme après cmd_ln_free_r(config), ne pas continuer l'exécution. Lorsque vous libérez config et essayez plus tard de l'utiliser, vous provoquez une violation de la mémoire.

+0

Merci! Je ne reçois plus l'erreur fatale. – PP600

+0

Mais comment puis-je définir le mode inmic et par exemple le chemin -hmm à la place? – PP600

+0

Vous n'avez pas besoin du mode inmic car votre code reconnaît le microphone par défaut. Vous pouvez configurer le chemin HMM dans le code avec l'appel de fonction 'cmd_ln_set_str_r' sur l'objet de configuration avant d'initialiser le décodeur avec' ps_init' –