2014-06-28 2 views
3

Quelqu'un peut-il m'expliquer comment je peux convertir mon discours en texte en utilisant pocketsphinx? J'essaie ceci:Le mot-clé n'est pas détecté à l'aide de pocketsphinx sur android

import com.example.speechtutor.SpeechRecognizerRecorder; 
import com.example.speechtutor.SpeechRecognizerRecorderSetup; 
import edu.cmu.pocketsphinx.Hypothesis; 
import edu.cmu.pocketsphinx.RecognitionListener; 
import static edu.cmu.pocketsphinx.Assets.syncAssets; 

public class SpeakActivity extends Activity implements RecognitionListener { 


SpeechRecognizerRecorder recognizer; 

private File appDir; 

String filePath; 

private static final String KWS_SEARCH_NAME = "wakeup"; 
private static final String FORECAST_SEARCH = "forecast"; 
private static final String DIGITS_SEARCH = "digits"; 
private static final String MENU_SEARCH = "menu"; 
private static final String KEYPHRASE = "hello"; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_speak); 

try { 
    Log.d("Tag","before trying to sync assets"); 
    appDir = syncAssets(getApplicationContext()); 
} catch (IOException e) { 
    throw new RuntimeException("failed to synchronize assets", e); 
} 

Log.d("TAG","before recognizer instantiaiton"); 
recognizer = SpeechRecognizerRecorderSetup.defaultSetup() 
      .setAcousticModel(new File(appDir, "models/hmm/en-us-semi")) 
      .setDictionary(new File(appDir, "models/lm/cmu07a.dic")) 
      .setRawLogDir(appDir) 
      .setKeywordThreshold(200) 
      .setAudioStorageDirectory("SpeechTutor") 
      .getRecognizer(); 




filePath = recognizer.getAudioStorageFilePath(); 

    recognizer.addListener(this); 
    // Create keyword-activation search. 
    File fillers = new File(appDir, "models/grammar/menu.gram"); 
    recognizer.addKeywordSearch(KWS_SEARCH_NAME, fillers.getPath()); 
    // Create grammar-based searches. 
    //File menuGrammar = new File(appDir, "models/grammar/menu.gram"); 
    //recognizer.addGrammarSearch(MENU_SEARCH, menuGrammar); 
    File digitsGrammar = new File(appDir, "models/grammar/digits.gram"); 
    recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar); 
    // Create language model search. 
    //digitsGrammar.File languageModel = new File(appDir, "models/lm/weather.dmp"); 
    //recognizer.addNgramSearch(FORECAST_SEARCH, languageModel); 

    recognizer.startListening(KEYPHRASE); 


} 

    @Override 
public void onPartialResult(Hypothesis arg0) { 
     String text = results.getHypstr(); 

    Log.d("Spoken text",text); 
    } 

    @Override 
public void onBeginningOfSpeech() { 
    } 

} 

Ce code fonctionne sans erreur, mais onPartialResult appel quand je dis « bonjour ». Mon application doit convertir chaque voix en texte. S'il vous plaît donnez-moi un échantillon.

+0

Je suis tellement satisfait que trouver développeur iranien qui font poche sphinix. jambon shoma être donble rahi baraye tarif "bonjour" budin. mishe lotfan farayandesho être manam commencer? kheyli recherche kardam o rahhaye zyadi emtehan kardam vali javab nadadan. http://stackoverflow.com/q/37629636/3671748 –

Répondre

8

Votre code contient plusieurs problèmes. Essayez des valeurs de seuil mot-clé comme 1E-60, 1E-40, 1E-20, 1E-10, certainement pas 200 dans cette ligne:

 .setKeywordThreshold(200) 

Si vous n'allez chercher mot-clé, il n'y a pas besoin de ce ligne avec la grammaire:

File digitsGrammar = new File(appDir, "models/grammar/digits.gram"); 
recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar); 

Cette partie ne semble pas raisonnable aussi bien. Recherche par mots clés prend une liste de mots à rechercher une ligne par non menu.gram fichier

File fillers = new File(appDir, "models/grammar/menu.gram"); 
recognizer.addKeywordSearch(KWS_SEARCH_NAME, fillers.getPath()); 

Si vous allez chercher juste pour un seul mot clé il n'y a pas besoin d'ajouter recherche par mot clé, vous ajoutez simplement la recherche keyphrase pour cette phrase

recognizer.addKeyphraseSearch(KWS_SEARCH_NAME, "hello"); 

Pour lancer la recherche du nom que vous pointez son nom, mot-clé pas itselsf:

recognizer.startListening(KWS_SEARCH_NAME); 

code correct devrait ressembler à ceci:

import com.example.speechtutor.SpeechRecognizerRecorder; 
import com.example.speechtutor.SpeechRecognizerRecorderSetup; 
import edu.cmu.pocketsphinx.Hypothesis; 
import edu.cmu.pocketsphinx.RecognitionListener; 
import static edu.cmu.pocketsphinx.Assets.syncAssets; 

public class SpeakActivity extends Activity implements RecognitionListener { 

SpeechRecognizerRecorder recognizer; 

private File appDir; 

private static final String KWS_SEARCH_NAME = "wakeup"; 
private static final String KEYPHRASE = "hello"; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_speak); 

    try { 
     Log.d("Tag","before trying to sync assets"); 
     appDir = syncAssets(getApplicationContext()); 
    } catch (IOException e) { 
     throw new RuntimeException("failed to synchronize assets", e); 
    } 

Log.d("TAG","before recognizer instantiaiton"); 
recognizer = SpeechRecognizerRecorderSetup.defaultSetup() 
      .setAcousticModel(new File(appDir, "models/hmm/en-us-semi")) 
      .setDictionary(new File(appDir, "models/lm/cmu07a.dic")) 
      .setRawLogDir(appDir) 
      .setKeywordThreshold(1e-40) 
      .setAudioStorageDirectory("SpeechTutor") 
      .getRecognizer(); 


    recognizer.addListener(this); 
    recognizer.addKeyphraseSearch(KWS_SEARCH_NAME, KEYPHRASE); 
    recognizer.startListening(KWS_SEARCH_NAME); 
} 

    @Override 
    public void onPartialResult(Hypothesis hyp) { 
     if (hyp == null) 
      return; 
     // Restart the recognition if keyword is found 
     String text = hyp.getHypstr(); 
     Log.d("Spoken text",text); 
     recognizer.cancel(); 
     recognizer.startSearch(KWS_SEARCH_NAME); 
    } 
} 
+0

Merci de votre réponse. Mais rien n'apparaît dans le journal sauf 'bonjour'. Pouvez-vous me donner un exemple complet? ou un projet Eclipse. –

+0

Exemple de quoi? –

+0

Regardez, RecognizerListener de google api écouter pour chaque voix, mais cette application écoute pour juste "bonjour" mot. C'est mon problème. Vu que vous êtes expert dans ce numéro. –

Questions connexes