本帖最后由 sangood 于 2018-11-15 12:15 编辑
前提:黑色主板,版本1.6.3 ,ssh 登录,参考:https://bbs.hassbian.com/thread-5149-1-1.html
风险提示: 楼主不负责,请注意变砖、不保修风险,wifi连不上风险!
目前问题:1 airplay时小爱无法调整音量(好像都不行),呼唤小爱,可以亮灯,没有声音回应。
2 安装包,没有添加卸载程序,请注意!
3.目前安装虫子的airplay插件(需要修改代码),可以发现了,但是tts播放目前没有声音。可以通过安装MPD方式,播放TTS了。
4.已经通过SSH方式,完美实现TTS了(播放音乐时自动暂停)。
‘
使用代码:
https://github.com/mikebrady/shairport-sync-for-openwrt
发现小爱可以运行这里的软件包:
https://archive.openwrt.org/chao ... 64/generic/packages
楼主下载了几个包,花了两天时间,整合了下:
一、步骤:
方式1:自己安装ipk包。
vi /etc/opkg.conf
#option check_signature 1
arch arm64 20
然后手工安装包,很多依赖包要安装,并且不能在线安装,只能先下载到本地安装。要是有大大编译meson平台的就好了。我忘记那些了,自己手工时试吧。里面还有一些坑!大概下面这些:
avahi-daemon-service-ssh - 0.6.31-10avahi-bus-daemon - 0.6.31-10libavahi-client - 0.6.31-10libavahi-bus-support - 0.6.31-10shairport
方式2:
下载安装包:放入/tmp/目录
tar -xf /tmp/shairport.tar
cd /tmp/shairport
chown root:root -R ./*
chmod 755 -R ./*
好像是下面这个命令拷贝(我自己不是这种方式安装的):
# cp -R * /
修改:
vi /etc/init.d/avahi-daemon
OPTIONS="-D --no-drop-root"
修改:
vi /etc/asound.conf
倒数第二行添加:
# add by sangood
pcm_slave.jabra {
pcm "hw:0,0"
rate 48000
}
pcm.airplay {
type rate
slave jabra
}
新增一个脚本文件,解决本地播放后,无法airplay的问题:
vi /root/active_airplay.sh
#!/bin/sh
/bin/ubus call mediaplayer player_play_operation {"action":"stop"} > /dev/null 2>&1
#/usr/bin/mphelper pause > /dev/null 2>&1
# exe this comand to active sound card
/bin/ubus call mibrain text_to_speech "{"text":"airplay","save":0}" > /dev/null 2>&1
exit 0
chmod +x /root/active_airplay.sh
vi /etc/init.d/shairport-sync
修改:
shairport-sync -d -a "$NAME" -B "/root/active_airplay.sh" -o alsa -S soxr -- -d airplay
启动:
/etc/init.d/dbus start
/etc/init.d/dbus enable
/etc/init.d/avahi-daemon enable
/etc/init.d/avahi-daemon start
/etc/init.d/shairport-sync enable
/etc/init.d/shairport-sync start
调试模式:
shairport-sync -vv -a MicoLR --statistics -o alsa -- -d airplay
shairport-sync -vvv -k -a MicoLR -B "/root/active_airplay.sh" --statistics -o alsa -S soxr -- -d airplay
清除垃圾:(mac下打包的,留了垃圾)
rm -rf /etc/avahi/._.DS_Store
rm -rf /etc/avahi/.DS_Store
rm -rf /etc/avahi/._avahi-daemon.conf
rm -rf /etc/avahi/._services
rm -rf /usr/bin/.DS_Store
rm -rf /usr/bin/._.DS_Store
rm -rf /usr/bin/._avahi*
rm -rf /usr/bin/._dbus*
rm -rf /usr/sbin/._avahi*
rm -rf /usr/bin/._dbus*
rm -rf /etc/.DS_Store
rm -rf /etc/._.DS_Store
rm -rf /etc/._dbus*
rm -rf /etc/._avahi*
rm -rf /etc/config/._shairport-sync
rm -rf /etc/init.d/._dbus*
rm -rf /etc/init.d/._avahi*
rm -rf /etc/init.d/._shairport-sync
rm -rf /etc/avahi/services/*._
rm -rf /etc/avahi/services/.DS_Store
文档:
我的整合的包,非安装包,需要传到小爱,拷贝到相关目录:
shairport.tar
(1.51 MB, 下载次数: 30)
二、安装MPD 播放TTS
安装mpd-mini 试试
wget --no-check-certificate [url=https://archive.openwrt.org/chaos_calmer/15.05/arm64/generic/packages/packages/mpd-mini_0.18.23-1_arm64.ipk]https://archive.openwrt.org/chao ... 0.18.23-1_arm64.ipk[/url]
opkg install --force-postinstall --nodeps mpd-mini_0.18.23-1_arm64.ipk
wget --no-check-certificate [url=https://archive.openwrt.org/chaos_calmer/15.05/arm64/generic/packages/packages/libmpdclient_2.10-1_arm64.ipk]https://archive.openwrt.org/chao ... nt_2.10-1_arm64.ipk[/url]
opkg install --force-postinstal libmpdclient_2.10-1_arm64.ipk --nodeps
wget --no-check-certificate [url=https://archive.openwrt.org/chaos_calmer/15.05/arm64/generic/packages/packages/libflac_1.3.1-1_arm64.ipk]https://archive.openwrt.org/chao ... c_1.3.1-1_arm64.ipk[/url]
opkg install --force-postinstal libflac_1.3.1-1_arm64.ipk --nodeps
wget --no-check-certificate [url=https://archive.openwrt.org/chaos_calmer/15.05/arm64/generic/packages/packages/libvorbisidec_1.0.3-20150104-1_arm64.ipk]https://archive.openwrt.org/chao ... 0150104-1_arm64.ipk[/url]
opkg install --force-postinstal libvorbisidec_1.0.3-20150104-1_arm64.ipk --nodeps
wget --no-check-certificate [url=https://archive.openwrt.org/chaos_calmer/15.05/arm64/generic/packages/packages/libogg_1.3.2-2_arm64.ipk]https://archive.openwrt.org/chao ... g_1.3.2-2_arm64.ipk[/url]
opkg install --force-postinstal libogg_1.3.2-2_arm64.ipk --nodeps
wget --no-check-certificate [url=https://archive.openwrt.org/chaos_calmer/15.05/arm64/generic/packages/packages/libmad_0.15.1b-3_arm64.ipk]https://archive.openwrt.org/chao ... 0.15.1b-3_arm64.ipk[/url]
opkg install --force-postinstal libmad_0.15.1b-3_arm64.ipk --nodeps
修改配置:
vi /etc/mpd.conf
input {
plugin "curl"
# proxy "proxy.isp.com:8080"
# proxy_user "user"
# proxy_password "password"
}
audio_output {
type "alsa"
name "My ALSA Device"
options "dev=dmixer"
mixer_control "Master" # optional
mixer_index "0" # optional
}
和shairport一样 需要拷贝音频定义文件:
cp /etc/diracmobile.config /usr/lib/diracmobile.config
三、打开夜灯功能:
首先能确保HA用户免密码登录小爱,每个人环境不一样,此处请自行google。参考# https://beenje.github.io/blog/po ... -via-lxc-container/
# 控制小爱音箱 灯光 命令
switch:
- platform: command_line
switches:
light_mico_master:
command_on: 'ssh [email protected] "nice -n-20 /bin/show_led 7"'
command_off: 'ssh [email protected] "ubus -t 1 call led shut"'
#command_state: ''
light_mico_livingroom:
command_on: 'ssh [email protected] "nice -n-20 /bin/show_led 7"'
command_off: 'ssh [email protected] "ubus -t 1 call led shut"'
#command_state: ''
另外一些灯光命令:
打开Led (蓝色呼吸灯)
/bin/show_led 3
打开 灯 第一个参数8 表示控制颜色的,第二个参数颜色值rgb
/bin/show_led 8 233,12,32
关闭:
/bin/shut_led 3
或者: /bin/show_led c
内部命令:
打开8个灯:
ubus -t 1 call led show "{"L":8}"
关闭8个灯
ubus -t 1 call led shut "{"L":8}"
打开led 颜色:打开Led (红色灯)
ubus -t 1 call led show "{"L":8,"rgb":"233,12,0"}"
/bin/show_led 8 3
ubus -t 1 call led show "{"L":8,"rgb":"133,123,0"}"
ubus -t 1 call led show "{"L":8,"rgb":"233,3,140"}"
闪烁灯,说话的时候使用的
nice -n-20 /bin/show_led 9
网络连接失败灯
/bin/show_led 10 1>/dev/null 2>/dev/null
/bin/shut_led 10 1>/dev/null 2>/dev/null
四、关闭开机铃声,随时开关机
vi /etc/init.d/wireless
boot_done 方法中 注释
#mphelper tone /usr/share/sound/bootup.mp3
echo "boot_done dont play bootup.mp3"
五、小爱本地TTS方法:
前提,实现ssh免密码登录,见上面
# 命令调用 播放器 播放 mp3 ,如果正在播放音乐,这样的命令小爱不能播放
# 调用方法
shell_command:
mico_livingroom_tts: "ssh [email][email protected][/email] '/root/text_to_mico.sh' '{{message}}' "
# 传入
script:
mico_livingroom_tts:
sequence:
- service: shell_command.mico_livingroom_tts
data_template:
message: '{{message}}'
# 调用script方法:
automation:
- alias: mico_speech_play_weather
trigger:
- platform: event
event_type: clic
event_data:
entity_id: binary_sensor.switch_158d0000f242f6
click_type: single
action:
- service: script.mico_livingroom_tts
data_template:
message: >
"现在天气情况,温度是{{states('sensor.m13_temperature')}}度,湿度是{{states('sensor.m13_humidity')}}度。"
小爱音箱:
root@mico:~# vi text_to_mico.sh
#!/bin/sh
/bin/ubus call mibrain text_to_speech "{\"text\":\"$1\",\"save\":0,\"play\":1,\"volume\":100}" > /dev/null 2>&1
如果已经安装airplay需要:root@mico:~# cat text_to_mico.sh
#!/bin/sh
/usr/bin/shairport-sync -D > /dev/null 2>&1
/bin/ubus call mibrain text_to_speech "{\"text\":\"$1\",\"save\":0,\"play\":1,\"volume\":100}" > /dev/null 2>&1
sleep 5
/usr/bin/shairport-sync -R > /dev/null 2>&1
exit 0
加权限:
chmod +x text_to_mico.sh
|