语音到文本在Android [英] Speech to Text on Android
问题描述
我期待创建一个应用程序,它具有语音到文本。
I am looking to create an app which has Speech to text.
我知道这种使用RecognizerIntent能力:<一href="http://android-developers.blogspot.com/search/label/Speech%20Input">http://android-developers.blogspot.com/search/label/Speech%20Input
I am aware of this kind of ability using the RecognizerIntent: http://android-developers.blogspot.com/search/label/Speech%20Input
不过 - 我不希望一个新的意图被弹出,我想要做的分析,我目前的应用程序中的某些点上,我不希望它弹出的东西了,说明它正在试图记录你的声音
However - I do not want a new Intent to be popped up, I want to do the analysis a certain points in my current app, and I dont want it to pop something up stating that it is currently attempting to record your voice.
有没有人对如何最好地做到这一点的任何想法。我也许想尝试狮身人面像4 - 但我不知道这是否会能够在Android上运行 - ?!有没有人有任何建议或经验
Has anybody any ideas on how best to do this. I was perhaps thinking of trying Sphinx 4 - but I dont know if this would be able to run on Android - has anyone got any advice or experience?!
我在想,如果我可以在这里改变code到也许没有打扰显示UI或按钮,只是做了处理:<一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html
I was wondering if I could alter the code here to perhaps not bothering to show the UI or button and just do the processing: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/VoiceRecognition.html
干杯,
推荐答案
如果你不想使用 RecognizerIntent
做语音识别,你仍然可以使用<一href="http://developer.android.com/reference/android/speech/SpeechRecognizer.html">SpeechRecognizer类来做到这一点。但是,使用该类更棘手比使用意向一点点。最后一点,我会强烈建议让用户知道他什么时候被记录,否则他可能很成立,当他终于找到了。
If you don't want to use the RecognizerIntent
to do speech recognition, you could still use the SpeechRecognizer class to do it. However, using that class is a little bit more tricky than using the intent. As a final note, I would highly suggest to let the user know when he is recorded, otherwise he might be very set up, when he finally finds out.
编辑:一个小例子启发(但改变)从<一个href="http://stackoverflow.com/questions/4559930/speechrecognizer-causes-anr-i-need-help-with-android-speech-api">this堆栈溢出进入
A small example inspired (but changed) from this stack overflow entry
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
"com.domain.app");
SpeechRecognizer recognizer = SpeechRecognizer
.createSpeechRecognizer(this.getApplicationContext());
RecognitionListener listener = new RecognitionListener() {
@Override
public void onResults(Bundle results) {
ArrayList<String> voiceResults = results
.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (voiceResults == null) {
Log.e(TAG, "No voice results");
} else {
Log.d(TAG, "Printing matches: ");
for (String match : voiceResults) {
Log.d(TAG, match);
}
}
}
@Override
public void onReadyForSpeech(Bundle params) {
Log.d(TAG, "Ready for speech");
}
@Override
public void onError(int error) {
Log.d(TAG,
"Error listening for speech: " + error);
}
@Override
public void onBeginningOfSpeech() {
Log.d(TAG, "Speech starting");
}
@Override
public void onBufferReceived(byte[] buffer) {
// TODO Auto-generated method stub
}
@Override
public void onEndOfSpeech() {
// TODO Auto-generated method stub
}
@Override
public void onEvent(int eventType, Bundle params) {
// TODO Auto-generated method stub
}
@Override
public void onPartialResults(Bundle partialResults) {
// TODO Auto-generated method stub
}
@Override
public void onRmsChanged(float rmsdB) {
// TODO Auto-generated method stub
}
};
recognizer.setRecognitionListener(listener);
recognizer.startListening(intent);
重要提示:运行从UI线程此code。
Important: Run this code from the UI Thread.
这篇关于语音到文本在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!