3782浏览
查看: 3782|回复: 1

[项目] sudo-萌兔化身语音助手

[复制链接]
本帖最后由 中二点 于 2019-5-21 11:16 编辑

sudo-萌兔化身语音助手图1

材料清单:
1: ReSpeaker 4-Mics线性阵列套件
https://www.seeedstudio.com/ReSp ... r-Raspberry-Pi.html
2: Raspberry Pi 3 Model B
3: Adafruit Mono 2.5W Class D Audio Amplifier - PAM8302
https://www.adafruit.com/product/2130

用到的软件:
1. Snips AIR
https://snips.ai/
2. Home Assisant
https://www.home-assistant.io/

用到的机器:
1. 激光切割机(市面是普通的型号都是可以的)

项目介绍:


这是一个私人的家庭助手
市面上其实已经有很多的语音助手了,他们一般都可以在智能手机或者一些其它设备上使用。他们已经可以实现很多的功能,但他们打数据基本上都会被上传至某一个云平台上,这会让数据一直处于一种很危险的境地。但是Snips可以帮助你建立属于自己的语音助手,只让他们在设备上进行运行(除非你希望你的数据可以在网络上进行更精准的查询),树莓派会是一个很好的搭载设备用来建立属于自己的语音助手。

这是一个没有性别的语音助手:
我认为一个既不是女声也不是男声的语音助手是我认为最理想的声音。我还起了一个很中性的名字Sudo。

“- Turn on the lights-...- Sudo, turn on the lights- Okay, turning on the lights”

环保的:

"Turn off the lights, this is not Versailles"这是作者原文中的话,我认为可能是一句老人言,大致的意思就是要节约用电,记得关灯。作者认为做为成年人其实就很少会有人提醒需要及时关灯,所以他给Sudo设置了会提醒及时关灯的程序,这一点上至少它是可以帮助作者更环保的。

总结:由于该项目涉及不同的组件,因此以下是相关部分的概述:

让你的家更加的智能

一:设置Snips

首先要做的是在Raspberry Pi上安装Snips  - 我用了Raspberry Pi 3 - B.我首先将最新版本的Raspbian下载并传到到SD卡上,在root过的SD卡上创建了一个名为ssh的空文件,另一个名为wpa_supplicant.conf,然后在弹出卡的期间我用了我的信用卡插在里面。完成启动后,您应该在本地网络上看到它,并且如果您使用的是Mac OS,则可以使用默认的用户名和密码(pi / rapsberry)和raspberrypi.local。之后,我按照这里给出的说明(https://docs.snips.ai/getting-started/quick-start-raspberry-pi)。

然后,您前往Snips控制台(https://console.snips.ai)创建一个新助手。 我使用的是法语,但您可以自由使用支持者中的任何一种。 我打电话给我的助手Sue-Do,并从Snips App Store 中找到了一个工具(Heure by Joseph - 可以让你询问Snips时间)。 然后您可以给助手添加技能。
sudo-萌兔化身语音助手图2


为了让你的语音助手可以听到你说话并回答你,扬声器、麦克风。我外接了一个扬声器到树莓派上来完成了这个功能。
sudo-萌兔化身语音助手图3

设置Home Assistant
sudo-萌兔化身语音助手图4

然后按照下面的顺序找到一个文件(/home/homeassistant/.homeassistant/configuration.yaml),加上以下的代码
[mw_shl_code=applescript,true]tradfri: host: IP_ADDRESS[/mw_shl_code]

连接Snips和Home Assistant
详细可见:https://www.home-assistant.io/components/snips/
[mw_shl_code=applescript,true]mqtt:
broker: 127.0.0.1
port: 1883[/mw_shl_code]

https://docs.snips.ai/articles/console/actions/skills
sudo-萌兔化身语音助手图5

然后在configuration.yaml 文件加上了以下代码:
[mw_shl_code=applescript,true]snips:
feedback_sounds: true
python_script:intent_script: !include intent_script.yaml[/mw_shl_code]
[mw_shl_code=applescript,true]ikealights:
speech:
type: plain
text: "OK, j'allume la lumière"
action:
- service: python_script.ikealights
data_template:
lamp_name: "{{ lamp_name }}"[/mw_shl_code]
[mw_shl_code=applescript,true]lamp_name = data.get('lamp_name')
if lamp_name is not None:
logger.info("turning on lamp {}".format(lamp_name))
service_data = {'entity_id': lamp_name, 'brightness': 255 }
hass.services.call('light', 'turn_on', service_data, False)[/mw_shl_code]

[mw_shl_code=applescript,true]ensor:
- platform: history_stats
name: streelight on today
entity_id: light.streetlight
state: 'on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'[/mw_shl_code]

[mw_shl_code=applescript,true]consumption: speech: type: plain text: La lampe a passé {{ states('sensor.streetlight_on_today') }} heures allumée aujourd''hui[/mw_shl_code]
sudo-萌兔化身语音助手图6sudo-萌兔化身语音助手图7

[mw_shl_code=applescript,true]streelight_overuse:
trigger: - platform: numeric_state entity_id: sensor.streetlight_on_today above: 3
sequence: service: snips.say_action data: text: 'Dis, tu veux pas éteindre ta lumière ?' intent_filter: - lightsTurnOff [/mw_shl_code]
sudo-萌兔化身语音助手图8sudo-萌兔化身语音助手图9sudo-萌兔化身语音助手图10sudo-萌兔化身语音助手图11sudo-萌兔化身语音助手图13sudo-萌兔化身语音助手图12


[mw_shl_code=applescript,true]- platform: history_stats
name: 'streetlight on today'
entity_id: 'light.streetlight_1'
state: 'on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
- platform: history_stats
name: 'streetlight on yesterday'
entity_id: 'light.streetlight_1'
state: 'on'
type: time
end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
duration:
hours: 24
- platform: history_stats
name: 'streetlight on this week'
entity_id: 'light.streetlight_1'
state: 'on'
type: time
start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
end: '{{ now() }}'
[/mw_shl_code]
[mw_shl_code=applescript,true]
qds_year = queried_date_string[0:4]

qds_month = queried_date_string[5:7]

qds_day = queried_date_string[8:10]

qds_hour = queried_date_string[11:13]

qds_min = queried_date_string[14:16]

qds_sec = queried_date_string[17:19]

  

queried_date = datetime.datetime(int(qds_year),int(qds_month),int(qds_day),int(qds_hour),int(qds_min),int(qds_sec))

delta = queried_date - datetime.datetime.now()

  

if(delta == -1)

service_data = {'text': "La lampe a passé {{ states('sensor.streetlight_on_today') }} heures allumée ajourd'hui" }

elif(delta == -2)

service_data = {'text': "La lampe a passé {{ states('sensor.streetlight_on_yesterday') }} heures allumée hier" }

elif(delta < -2 and delta >-9)

service_data = {'text': "La lampe a passé {{ states('sensor.streetlight_on_yesterday') }} heures allumée cette semaine" }

else

service_data = {'text':"Je ne peux comprends pas cette date"} [/mw_shl_code]
[mw_shl_code=applescript,true]consumption:

speech:

   type: plain

   text: "Je consulte mes archives, ne bouge pas"

action:

   - service: python_script.consumptionhistory

     data_template:

       date: "{{ date }}"[/mw_shl_code]
sudo-萌兔化身语音助手图14sudo-萌兔化身语音助手图15sudo-萌兔化身语音助手图16sudo-萌兔化身语音助手图17

[mw_shl_code=applescript,true]homeassistant:
name: 1921
latitude: 48.8543
longitude: 2.3527
elevation: 0
unit_system: metric
time_zone: Europe/Paris
customize: !include customize.yaml

default_config:

sensor:
- platform: yr

- platform: history_stats
name: 'streetlight on today'
entity_id: 'light.streetlight_1'
state: 'on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'


mqtt:
broker: 127.0.0.1
port: 1883

snips:
feedback_sounds: true

python_script:

intent_script: !include intent_script.yaml
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

#introduction:

#discovery:[/mw_shl_code]
sudo-萌兔化身语音助手图18sudo-萌兔化身语音助手图19sudo-萌兔化身语音助手图20

原文:https://www.hackster.io/jessyjones/sudo-a-private-by-design-gender-neutral-eco-friendly-bot-bd8d85

pATAq  版主

发表于 2019-9-18 16:00:56

很不错的教程,感谢编译
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail