问题描述
在softkeyboard我对语音到文本,当我谈到它显示的建议名单,当我选择一文中,我需要填补我与这段文字EDITTEXT的选项,我怎么能做到这一点,我有看到SpeechRecognizer类,我不知道我可以利用这一点,请大家帮我
SpeechRecognizer REC = SpeechRecognizer.createSpeechRecognizer(背景); RecognitionListener监听器=新RecognitionListener(){ @覆盖
公共无效onRmsChanged(浮动rmsdB){
} @覆盖
公共无效onResults(捆绑的结果){
ArrayList的<串GT; voiceResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
} @覆盖
公共无效onReadyForSpeech(捆绑PARAMS){
// TODO自动生成方法存根 } @覆盖
公共无效onPartialResults(捆绑partialResults){
} @覆盖
公共无效的onEvent(INT EVENTTYPE,捆绑PARAMS){
} @覆盖
公共无效onerror的(INT ERROR){
} @覆盖
公共无效onEndOfSpeech(){
} @覆盖
公共无效onBufferReceived(字节[]缓冲区){
} @覆盖
公共无效onBeginningOfSpeech(){
}
};
rec.setRecognitionListener(监听);
假设你的文本编辑被命名为TE:
公共无效onResults(捆绑的结果){
ArrayList的<串GT; voiceResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
StringBuilder的SB =新的StringBuilder();
对(串P:voiceResults){
sb.append(P);
sb.append(\\ n); } te.setText(sb.toString());
}
通常情况下,你只能在第一个结果感兴趣(即voiceResults(0)),因为这是最有可能的比赛,但在code上面显示所有的人,所以你可以看到返回什么。
in softkeyboard i have the option for speech to text , when i spoke it show a list of suggestion , when i select a text ,i need to fill my editText with this text, how can i done this i have see SpeechRecognizer class ,i don't know how can i use this ,please help me
SpeechRecognizer rec=SpeechRecognizer.createSpeechRecognizer(context);
RecognitionListener listener = new RecognitionListener() {
@Override
public void onRmsChanged(float rmsdB) {
}
@Override
public void onResults(Bundle results) {
ArrayList<String> voiceResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
}
@Override
public void onReadyForSpeech(Bundle params) {
// TODO Auto-generated method stub
}
@Override
public void onPartialResults(Bundle partialResults) {
}
@Override
public void onEvent(int eventType, Bundle params) {
}
@Override
public void onError(int error) {
}
@Override
public void onEndOfSpeech() {
}
@Override
public void onBufferReceived(byte[] buffer) {
}
@Override
public void onBeginningOfSpeech() {
}
};
rec.setRecognitionListener(listener);
Assuming your text edit is named "te":
public void onResults(Bundle results) {
ArrayList<String> voiceResults = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
StringBuilder sb = new StringBuilder();
for(String p: voiceResults) {
sb.append(p);
sb.append("\n"); } te.setText(sb.toString());
}
Normally, you are only interested in the first result (i.e voiceResults (0)) since that is the most probable match but the code above shows all of them so you can see what is returned.
这篇关于Android的语音到文本处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!