(红灯后识别二秒钟)
https://v.youku.com/v_show/id_XNDY4MzE1MjEyNA==.html?spm=a2h0c.8166622.PhoneSokuUgc_1.dtitle
https://v.youku.com/v_show/id_XNDY4MzE1MjEyNA==.html?spm=a2h0c.8166622.PhoneSokuUgc_1.dtitle
10、语音控制开灯与关灯
——简单在线模式,反应有点慢,语音识别“开灯”,任意语音关灯。这个方案打开灯有点难,需要准确发音“开灯”二个字,反之关灯很容易,说什么都可以关灯,便于节约用电。
#MicroPython动手做(25)——语音合成与语音识别
#语音控制开灯与关灯(简单在线模式,反应有点慢)
from mpython import *
import network
import music
import time
import audio
import urequests
import json
import machine
import ubinascii
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
def on_button_a_down(_):
time.sleep_ms(10)
if button_a.value() == 1: return
rgb = (int(102), int(0), int(0))
rgb.write()
time.sleep_ms(1)
if get_asr_result(2) == "开灯":
rgb.fill((int(51), int(102), int(255)))
rgb.write()
time.sleep_ms(1)
music.play('D5:1')
oled.fill(0)
oled.blit(image_picture.load('face/Objects/Light on.pbm', 0), 32, 0)
oled.show()
else:
rgb.fill( (0, 0, 0) )
rgb.write()
time.sleep_ms(1)
music.play('B5:1')
oled.fill(0)
oled.blit(image_picture.load('face/Objects/Light off.pbm', 0), 32, 0)
oled.show()
def get_asr_result(_time):
audio.recorder_init()
audio.record("temp.wav", int(_time))
audio.recorder_deinit()
_response = urequests.post("http://119.23.66.134:8085/file_upload",
files={"file":("temp.wav", "audio/wav")},
params={"appid":"1", "mediatype":"2", "deviceid":ubinascii.hexlify(machine.unique_id()).decode().upper()})
rsp_json = _response.json()
_response.close()
if "text" in rsp_json:
return rsp_json["text"]
elif "Code" in rsp_json:
return "Code:%s" % rsp_json["Code"]
else:
return rsp_json
image_picture = Image()
button_a.irq(trigger=Pin.IRQ_FALLING, handler=on_button_a_down)
oled.fill(0)
oled.DispChar("按下A键开始语音控制", 0, 16, 1)
oled.show()
music.play('G5:1')
rgb = (int(0), int(51), int(0))
rgb.write()
time.sleep_ms(1)
mPython X 图形编程
#MicroPython动手做(25)——语音合成与语音识别
#语音控制开灯与关灯(简单在线模式,反应有点慢)-视频
https://v.youku.com/v_show/id_XNDY4MzM5OTY1Ng==.html?spm=a2h0c.8166622.PhoneSokuUgc_1.dtitle
https://v.youku.com/v_show/id_XNDY4MzM5OTY1Ng==.html?spm=a2h0c.8166622.PhoneSokuUgc_1.dtitle
今天再次测试语音合成,不知为何一直报错,出错信息为:
刷入成功
Connection WiFi....
WiFi(zhz,-64dBm) Connection Successful, Config:('192.168.31.25', '255.255.255.0', '192.168
.31.34', '192.168.31.34')
(2020, 6, 15, 8, 28, 32, 0, 167)
Processing, please wait....
Traceback (most recent call last):
File "main.py", line 24, in <module>
File "xunfei.py", line 208, in tts
File "uwebsockets/client.py", line 62, in connect
Assertion Error: b'HTTP/1.1 403 Forbidden'
MicroPython v2.0.1-18-gbe8fbdd-dirty on 2020-04-24; mpython with ESP32
Type "help()" for more information.
>>>
>>>
页:
1
[2]