首页 存档 技术 查看内容

如何将AI原生的应用到Android系统?

2018-3-30 13:00 |来自: 互联网 497 0

摘要: 相较于阅读消息内容,直接听取内容无疑更为便捷。将沃森的文本到语音功能集成至现有Android原生应用中能够帮助大家轻松实现这一目标。 在今天的文章中,我们将探讨如何将沃森文本到语音(简称TTS)功能集成至现有And ...

相较于阅读消息内容,直接听取内容无疑更为便捷。将沃森的文本到语音功能集成至现有Android原生应用中能够帮助大家轻松实现这一目标。

在今天的文章中,我们将探讨如何将沃森文本到语音(简称TTS)功能集成至现有Android原生移动应用当中。

在第一次尝试向GitHub提交自己开发的Watbot时,这样的经历简直可以用“梦幻般”来形容。Watbot是一款利用沃森对话服务打造的Android聊天机器人,主要帮助高校学生们学习如何在30分钟内通过在Bluemix上创建服务并经由模拟器或者物理设备运行应用,最终实现学习目标。不过在我看来,将其它沃森服务集成至应用当中显然更为有趣,特别是沃森文本到语音服务。相较于阅读消息内容,直接听取其内容无疑更加便捷。

“文本到语音转换能够将书面文本转化为自然发声音频。您可以自定义并控制特定词汇的发音,从而为受众提供无缝化语音交互成果,其适用于儿童互动玩具、自动呼叫中心交互以及免提式导航系统。”

以不同语音听取消息内容

  • 在Bluemix上创建一项沃森文本到语音(简称TTS)服务。

  • 前往Service Credentials标签并点击View Credentials。

curl-XGET-u"{username}":"{password}" "https://stream.watsonplatform.net/text-to-speech/api/v1/voices"

以上代表用于检索全部可用于服务的语音列表。其中提供的信息包括语音名称、语种以及性别等等。要了解关于特定语音的信息,请使用“Get a voice”方法:

{ "voices":[ { "name":"pt-BR_IsabelaVoice", "language":"pt-BR", "customizable":true, "gender":"female", "url":"https://stream-s.watsonplatform.net/text-to-speech/api/v1/voices/pt-BR_IsabelaVoice", "supported_features":{ "voice_transformation":false, "custom_pronunciation":true }, "description":"Isabela:BrazilianPortuguese(portuguêsbrasileiro)femalevoice." }, { "name":"es-US_SofiaVoice", "language":"es-US", "customizable":true, "gender":"female", "url":"https://stream-s.watsonplatform.net/text-to-speech/api/v1/voices/es-US_SofiaVoice", "supported_features":{ "voice_transformation":false, "custom_pronunciation":true }, "description":"Sofia:NorthAmericanSpanish(espaolnorteamericano)femalevoice." }, { "name":"en-GB_KateVoice", "language":"en-GB", "customizable":true, "gender":"female", "url":"https://stream-s.watsonplatform.net/text-to-speech/api/v1/voices/en-GB_KateVoice", "supported_features":{ "voice_transformation":false, "custom_pronunciation":true }, "description":"Kate:BritishEnglishfemalevoice." }, { "name":"en-US_LisaVoice", "language":"en-US", "customizable":true, "gender":"female", "url":"https://stream-s.watsonplatform.net/text-to-speech/api/v1/voices/en-US_LisaVoice", "supported_features":{ "voice_transformation":true, "custom_pronunciation":true }, "description":"Lisa:AmericanEnglishfemalevoice." }, { "name":"ja-JP_EmiVoice", "language":"ja-JP", "customizable":true, "gender":"female", "url":"https://stream-s.watsonplatform.net/text-to-speech/api/v1/voices/ja-JP_EmiVoice", "supported_features":{ "voice_transformation":false, "custom_pronunciation":true }, "description":"Emi:Japanese(日本)femalevoice." }, ... ] }

感兴趣的朋友可以点击此处参阅沃森开发者云之上的API参考资料,从而了解更多与TTS API调用相关的知识

如何将TTS集成至我的Android原生应用?

这要求我们将TTS的Gradle条目添加至build.gradle(应用)文件当中:

compile'com.ibm.watson.developer_cloud:text-to-speech:3.5.3' compile'com.ibm.watson.developer_cloud:android-sdk:0.2.1'

在您的MainActivity.java文件内添加以下代码,并将用户名与密码占位符替换为实际TTS服务凭据。另外,在添加以下代码后,点触一段消息即可将文本转换为语音:

recyclerView.addOnItemTouchListener(newRecyclerTouchListener(getApplicationContext(),recyclerView,newClickListener(){ @Override publicvoidonClick(Viewview,finalintposition){ Threadthread=newThread(newRunnable(){ publicvoidrun(){ MessageaudioMessage; try{ audioMessage=(Message)messageArrayList.get(position); streamPlayer=newStreamPlayer(); if(audioMessage!=null

声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

相关分类

返回顶部