.android 语音(声音)转文字
16lz
2021-01-26
public class SoundTestActivity extends Activity {
/** Called when the activity is first created. */
private static final int RECOGNIZER_EXAMPLE=101;
private TextView result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
result=(TextView)findViewById(R.id.text_result);
Button start=(Button)findViewById(R.id.start_button);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word or phrase\nand it will show as text");
startActivityForResult(intent,RECOGNIZER_EXAMPLE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode==RECOGNIZER_EXAMPLE&&resultCode==RESULT_OK){
ArrayList<String> resultList=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
StringBuffer resultListString=new StringBuffer();;
for(String s:resultList){
resultListString.append(s+",");
}
result.setText(resultListString.toString());
}
super.onActivityResult(requestCode, resultCode, data);
}
}
/** Called when the activity is first created. */
private static final int RECOGNIZER_EXAMPLE=101;
private TextView result;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
result=(TextView)findViewById(R.id.text_result);
Button start=(Button)findViewById(R.id.start_button);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word or phrase\nand it will show as text");
startActivityForResult(intent,RECOGNIZER_EXAMPLE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode==RECOGNIZER_EXAMPLE&&resultCode==RESULT_OK){
ArrayList<String> resultList=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
StringBuffer resultListString=new StringBuffer();;
for(String s:resultList){
resultListString.append(s+",");
}
result.setText(resultListString.toString());
}
super.onActivityResult(requestCode, resultCode, data);
}
}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer