本教程展示瞭如何使用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中文網其他相關文章!