[已解决]行空板不能播放语音合成的文件音频
本帖最后由 刘骏森 于 2024-5-20 19:58 编辑我发现我今天在用行空板使用aip的时候不能播放语音合成的音频,以下是错误信息:
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1
record.mp3: Invalid argument
求大佬们帮我解决一下问题
错误行:
with open("record.mp3","wb") as fp:
->fp.write(json.dumps(text).encode()) 这样也会报错:
with open("record.mp3","wb") as fp:
->fp.write(text)
TypeError: a bytes-like object is required, not 'dict' 错误信息是无法对record.mp3文件进行解码,完整程序发出来看看。 from unihiker import *
from pinpong.board import *
from aip import AipSpeech
import json
audio = Audio()
cilent = AipSpeech("","","")
text = cilent.synthesis("你好", "zh", 1, {"vol": 5,"spd": 5,"pit": 3,"per": 0})
with open("record.mp3","wb") as fp:
fp.write(str(text).decode())
audio.play("record.mp3")
Board().begin()
pin1 = Pin(Pin.D24,Pin.IN)
dht = DHT11(pin1)
gui = GUI()
t = gui.draw_text(text=dht.temp_c(),x=0,y=0,color="#0000FF")
while True:
t.config(text=dht.humidity())
代码发错了,第11行fp.write(str(text).encode())改成fp.write(json.dumps(text).encode()) 解决了,是网络问题,请求不到<div class="reference"><p><a href="https://mc.dfrobot.com.cn/home.php?mod=space&uid=857409&do=profile" target="_blank">刘骏森</a> 2024-03-03 09:43:22<p><div class="quote">代码发错了,第11行fp.write(str(text).encode())改成fp.write(json.dumps(text).encode())</div></div>
页:
[1]