ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android语音播报、后台播报、语音识别,移动开发工程师核心竞争力

2022-01-19 16:00:27  阅读:217  来源: 互联网

标签:播报 layout text id 语音 wrap Android 识别 android


android:text=“识别” />

<Button

android:id="@+id/bt_speek"

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:text=“Speek” />

<Button

android:id="@+id/bt_speek_bg"

android:layout_width=“fill_parent”

android:layout_height=“wrap_content”

android:gravity=“center”

android:text=“后台Speek” />

<TextView

android:textColor="@android:color/white"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“语音控制开关” />

<ToggleButton

android:id="@+id/tb"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content” />

识别

==

case R.id.bt_recognize:

// 这是语言识别部分,最重要的实例化一个

// RecognizerDialog并把你在官方网站申请的appid填入进去,非法id不能进行识别

RecognizerDialog isrDialog = new RecognizerDialog(Voice1Activity.this, APPID);

/*

  • 设置引擎目前支持五种 ”sms”:普通文本转写 “poi”:地名搜索 ”vsearch”:热词搜索

  • ”video”:视频音乐搜索 ”asr”:命令词识别

*/

isrDialog.setEngine(“sms”, null, null);

isrDialog.setListener(recoListener);

isrDialog.show();

break;

// 语言识别监听器,有两个方法

RecognizerDialogListener recoListener = new RecognizerDialogListener() {

@Override

public void onResults(ArrayList results,

boolean isLast) {

// 新增加了一个ToggleButton tb,首先检查tb是否被按下,如果被按下才进行语言控制,没被按下就进行文字识别

if (tb.isChecked()) {

// doVoice方法就是进行识别

doVoice(results);

} else {

// 服务器识别完成后会返回集合,我们这里就只得到最匹配的那一项

text += results.get(0).text;

System.out.println(text);

}

}

// 首先迭代结果,然后获取每个结果,并进行对比,如果包含有特定字符串,那么就执行相应Intent跳转。

// 注意 凡是Intent能办到的(发邮件,跳到已安装应用,拨号,发短信,发彩信,浏览网页,播放多媒体),它就都能办到。

private void doVoice(ArrayList results) {

Intent i = new Intent();

for (RecognizerResult result : results) {

if (result.text.contains(“天气”)) {

// 天气界面的跳转

i.setClass(Voice1Activity.this, Weather.class);

startActivity(i);

} else if (result.text.contains(“新闻”)) {

// 新闻界面的跳转

i.setClass(Voice1Activity.this, News.class);

startActivity(i);

} else if (result.text.contains(“短信”)) {

// 短信界面的跳转

i.setAction(Intent.ACTION_VIEW);

i.setType(“vnd.android-dir/mms-sms”);

startActivity(i);

} else {

// 如果没有相应指令就用Toast提示用户

Toast.makeText(Voice1Activity.this, “无法识别”,Toas
t.LENGTH_SHORT).show();

}

}

}

@Override

public void onEnd(SpeechError error) {

if (error == null) {

// 完成后就把结果显示在EditText上

et.setText(text);

}

}

};

Speek

)]
t.LENGTH_SHORT).show();

}

}

}

@Override

public void onEnd(SpeechError error) {

if (error == null) {

// 完成后就把结果显示在EditText上

et.setText(text);

}

}

};

Speek

标签:播报,layout,text,id,语音,wrap,Android,识别,android
来源: https://blog.csdn.net/m0_66264324/article/details/122582792

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有