参考:
http://bbs.elecfans.com/jishu_543262_1_1.html
配置:
喇叭:3.5音频口
麦克风:摄像头自带麦克风(Usb)
1. 安装需要的软件
1 | sudo apt-get install python-pip mplayer flac python2.7-dev libcurl4-gnutls-dev |
2. 配置配置麦克风和音箱
1 | $ cat /proc/asound/cards |
第一个命令查看声卡是否存在
第二个命令应该是看声卡的驱动的
调整输入输出音频工具alsamixer:
sudo alsamixer
3. 播放声音
aplay make.wav
结果声音没有播放
网上查了,
By default output will be automatic (hdmi if hdmi supports audio, otherwise analogue). You can force it with:
amixer cset numid=3
where n is 0=auto, 1=headphones, 2=hdmi.
If you have pulseaudio installed you need to also specify the card number:
amixer -c 0 cset numid=3
http://elinux.org/R-Pi_Troubleshooting#Sound_does_not_work_at_all.2C_or_in_some_applications
所以运行
amixer cset numid=3 1
就可以听到3.5输出了
4. 麦克风测试
sudo arecord –duration=10 –device=plughw:1,0 –format=cd aaa.wav
指令中的’–device=plughw:1,0’ 选项指派特定的录音设备,而Raspberry Pi的内置音效设备是’plughw:0,0’
使用百度api进行语音播放:
5. 使用百度API进行语音识别和播放
http://yuyin.baidu.com/docs/tts/135
测试取的token:
1 | import requests |
测试ok后,开始正式写:
https://github.com/xuqi1987/10.voice
大致思路:
将请求的token保存到文件中,然后读取文件中的accesstoken,判断token的日期是否有效,无效重新请求token。
代码:
app.py
1 | # -*- coding:utf8 -*- |
baidu.py
1 | # -*- coding:utf8 -*- |
遇到坑:
- mp3格式只能通过mpg321播放
- 读取文件token = file.readlines()[0],是一个列表,所以需要先取第一个再用json转。