在轻量级树莓派系统DietPi上安装和配置DuerOS的方法

现在树莓派的使用越来越广泛,所以Raspberry官网方面也根据大家的需要和建议一点点在完善和升级,在这过程中难免会往树莓派系统里添加各种个样的服务来满足大家的需求。但这样也对于那些只需要简单单一服务的应用场景来说却显得有些臃肿,所以这个时候社区就开发出了基于Raspbian系统的精简版DietPi系统出来。这个系统裁剪了很多不必要的服务,只保留了以前Raspbian一些必要的软件和服务。这次我们将把DuerOS安装到这个系统上,让你的设备更加的专业和轻量。


(一)安装依赖包和DuerOS运行环境
因为这个DietPi系统裁剪了很多服务,所以在安装DuerOS这个服务前我们还是需要安装一些必要的服务才行。这里我们列出了一些DuerOS需要用到的资源,通过在线安装即可。
sudo apt-get install vim
sudo apt-get install gir1.2-gstreamer-1.0
sudo apt-get install libatlas-base-dev
sudo apt-get install python-dateutil
sudo apt-get install python-pyaudio
sudo apt-get install python-dev 
apt-get install python-pip    
sudo pip install tornado
sudo pip install hyper
pip install gi
pip install requests
pip install sokit


可能遇到的错误和解决方法:
这要把tornado拿出来单独讲一下,因为在安装时可能会报错提示;error: invalid command 'bdist_wheel'
如果碰到这个问题则需要升级pip和setuptools两个服务,具体命令如下;
pip install setuptools --upgrade
pip install pip --upgrade
升级完pip后因为还有以前旧版本的pip缓存的原因,所以直接使用会报ImportError: cannot import name main类型错误。
这个时候执行命令hash -d pip删除以前老版本的缓存即可。

在上面完成python-pyaudio我们就可以开始使用pyaudio服务了
运行命令pip install pyaudio 会提示ImportError: No module named setuptools方面的错误。这是因为缺少setuptools的缘故,我们使用pip命令pip install setuptools安装即可。
如果在安装过程中提示如下错误,说gcc等目录没找到。
unable to execute 'arm-linux-gnueabihf-gcc': No such file or directory
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-Ym4Ons/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-UrQ3g3/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-Ym4Ons/pyaudio/
那么我们就还需要来单独安装arm-gcc版本,因为在安装上面服务的时候需要用到编译器,通过在线安装命令apt-get install python-audio即可。


(二)下载安装并配置DuerOS
这里我们通过github开源项目,在树莓派上直接下载DuerOS相关服务,具体操作命令如下;
git clone https://github.com/MyDuerOS/DuerOS-Python-Client.git //在线克隆DuerOS-Python-Client到本地
cd DuerOS-Python-Client //进入刚才的下载目录
git checkout raspberry-dev //开始checkout

下载后的python源代码不能直接使用,首先要用VIM打开DuerOS-Python-Client/sdk/auth.py文件将CLIENT_ID CLIENT_SECRET改为你的开放平台内设备配置信息。
因为dietpi是裁剪的系统所以没有桌面系统也没有浏览器,所需要修改配置使用同局域网的其他电脑浏览器来登录,我们通过修改webbrower.open("http://pi.local:3000"),并在你局域网的电脑上修改hosts文件来配置pi.local hosts指向树莓派网卡上的局域网ip地址。

执行 enter_trigger_start.sh 
然后我们进入X环境下执行jack_control start pulseaudio --start 命令后,提示启动成功。

可能遇到的错误和解决方法:
如果执行 enter_trigger_start.sh 报错
Traceback (most recent call last):
File "./app/enter_trigger_main.py", line 9, in <module>
from app.framework.player import Player
File "/root/Dueros/DuerOS-Python-Client/app/framework/player.py", line 10, in <module>
from gi.repository import Gst
ImportError: No module named repository
提示上面的错误是因为确实gi等一些模块我们在线安装apt-get install python-gobject-2-dev python-gi-dev即可。

关于错误提示;ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
运行命令pulseaudio --start 
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started//提示jackd服务没有开启
解决方法命令启动 jackd  -d dummy即可。

Could not read result type = 22
Client name = PortAudio conflits with another running client
Cannot connect to the server
ALSA lib pcm.c:7843:(snd_pcm_recover) underrun occurred
The underun is likely caused because pulseaudio is already accessing the card - you can pause it using http://linux.die.net/man/1/pasuspender. In general to avoid such deadlock, you need a soundserver like jackd https://help.ubuntu.com/community/What%20is%20JACK, but you already figured this out from the following log entries in your trace ;-) (apt-get install jackd)
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave"
You need to change "pcm.front cards.pcm.front" to "pcm.front cards.pcm.default" in /usr/share/alsa/alsa.conf.
The rest of the errors are not meaningful, for instance, "bt_audio_service_open: connect() failed: Connection refused (111)" refers to your bluetooth device - you are likely missing some bluethooth packages, but you can simply ignore it.
This should get you moving forward and debug further.
import pyaudio //载入pyaudio模块
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
dev = p.get_device_info_by_index(i)
print((i,dev['name'],dev['maxInputChannels']))


其他信息
树莓派ip配置文件地址/etc/network/interfaces
ALSA模块索引设置 /etc/modprobe.d/alsa-base.conf
主路径/usr/share/alsa
设备路径/proc/asound
修改pi.local地址C:\Windows\System32\drivers\etc


总结
虽然DietPi确实轻量但是去掉很多运行环境和服务的情况,需要自己动手安装和配置的话对与小白和刚入门的人还是有点难度。但是通过这种方式安装DuerOS能让我们更加了解Linux系统和DuerOS的原理和结构。最后小伙伴们如果有任何问题欢迎随时加入牛人技术博客群一起来讨论交流。


本文由作者自行上传发布,文章仅代表作者个人观点。如需转载,务必声明出处和网址,否则保留相关权利。

网友评论 comments

发表评论

电子邮件地址不会被公开。必填项已用 *标注

暂无评论

牛人技术博客 | About US | 湘ICP备13000282号-8 |
Copyright © 2009 - 2023 NRJS Corporation, All Rights Reserved
添加图标到手机桌面
扫二维码
扫二维码
返回顶部