本教程展示了如何使用IBM Watson的文本到语音服务和Node-red进行Raspberry Pi谈话。 我们将在上一个示例上构建(假定先前的Raspberry Pi,Bluemix和Node-Red设置)。 SitePoint/patcat的艺术品,徽标权利:IBM和Raspberry Pi Foundation
>
>在蓝色中启用文本到语音:
>
>安装ALSA库:cd ~/.node-red
安装ALSA库进行音频播放:sudo npm install node-red-node-watson
。重新启动node-red(
>创建节点 - 雷德流:sudo apt-get install libasound2-dev
将以下节点添加到您的节点 - red流:node-red-stop; node-red-start
<code>* **Function Node ("Temperature Text"):** Format the temperature data (from a previous "getCPUTemp" node, assumed to exist) into a human-readable sentence: ```javascript msg.payload = "My current CPU temperature is " + msg.payload.replace("temp=","").replace("'C\n","") + " degrees celsius"; return msg; ``` * **Function Node ("Format Speech"):** Prepare the speech message: ```javascript msg.payload = msg.speech; return msg; ``` * **File Node ("Create WAV"):** Save the generated audio to `/home/pi/temp/speech.wav`. Ensure "Create directory if it doesn’t exist" is checked and "Add newline" is unchecked.</code>
配置音频输出:
<code>* **Delay Node:** Add a 1-second delay to allow the audio file to be created. * **File Node ("Read WAV"):** Read the audio file from `/home/pi/temp/speech.wav` as a buffer. * **Exec Node ("Play Audio"):** Play the audio using `aplay /home/pi/temp/speech.wav`.</code>
故障排除和常见问题解答:
以上是教您的Raspberry Pi与IBM Watson交谈的详细内容。更多信息请关注PHP中文网其他相关文章!