本文主要是介绍使用baidu_speech让你的机器人开口说话 语音交互,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考张瑞雷老师的博文
在ROS中使用中文语音交互(百度语音baidu_speech)
http://blog.csdn.net/zhangrelay/article/details/78867450
百度语音包
http://wiki.ros.org/baidu_speech
https://github.com/DinnerHowe/baidu_speech
语音节点订阅了speak_string主题。
如图
向主题发布文本字符串 就可以听到文本的语音了。
语音节点应该是将字符串发送给后台接口传回mp3保存并播放。
this package is python package for ROS speech, which use online baidu speech to do TTS and speech recognition.
this code is run well in ubuntu 14.04, thinkpad T44s.
you can visit the baidu speech home page at here: http://yuyin.baidu.com/
并且这个包可以做在线的语音识别。
可以在识别节点把识别出的文本发布到speak_string话题。这样就可以同时测试speech recognition和tts两个功能了。
安装两个必须的Python库pyaudio和python-vlc(安装vlc遇到问题见下文)
$ sudo apt-get install python-pip portaudio19-dev vlc libvlc-dev
$ sudo pip install pyaudio
$ sudo pip install python-vlc
下载包并编译完成
在运行Python程序时提示:
import requests
ImportError: No module named requests
解决
Requests is not a built in module, so you will have to download it. You can get it here:https://pypi.python.org/pypi/requests
$ sudo pip install requests
错误
requests.exceptions.InvalidHeader:Value for header{Content-length:37523} must be of type str or bytes, not <type 'int'>
解决
voice_node.py
HTTP_HEADER= { 'Content-Type': 'audio/%s;rate=%s'%(self.FORMAT,self.SAMPLING_RATE),'Content-length': len(json.dumps(RegData))}#改为
HTTP_HEADER= { 'Content-Type': 'audio/%s;rate=%s'%(self.FORMAT,self.SAMPLING_RATE),'Content-length': str(len(json.dumps(RegData)))}
错误
KeyError 3312
解决
def define(self):self.error_reason={3300: '输入参数不正确',3301: '识别错误',3302: '验证失败',3303: '语音服务器后端问题',3304: '请求 GPS 过大,超过限额',3305: '产品线当前日请求数超过限额',3312: 'param format invalid'}
ros版本kinetic
系统是ubuntu 16.04
其中 vlc 出错
下列软件包有未满足的依赖关系:
vlc : 依赖: libgles1-mesa (>= 7.8.1) 但是它将不会被安装 或
libgles1
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。
解决
http://ubuntuhandbook.org/index.php/2017/05/install-vlc-2-2-5-in-ubuntu-16-04-14-04/
引用
How to Install VLC 2.2.5 in Ubuntu / Linux Mint:
Besides building VLC 2.2.5 from the source tarball, Ubuntu 14.04, 16.04, and Linux mint 18 users can install it from the unofficial PPA.
1. Open terminal via Ctrl+Alt+T or by searching “Terminal” from start menu. When it opens, run command to add PPA:
sudo add-apt-repository ppa:jonathonf/vlc
Type in your password (no visual feedback due to security reason) when prompts and hit Enter.
VLC 2.2.5 PPA
2. (IMPORTANT) Remove old VLC version to avoid a package conflict:
sudo apt remove vlc vlc-nox
3. Finally run commands in terminal to check updates and install VLC 2.2.5:
sudo apt update && sudo apt install vlc
How to Restore:
To restore VLC media player to the stock version in your main Ubuntu repository, run command to purge the PPA:
sudo apt install ppa-purge && sudo ppa-purge ppa:jonathonf/vlc
这篇关于使用baidu_speech让你的机器人开口说话 语音交互的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!