我試圖爲我的祖父創建一個簡單的音樂播放器,通過編程音頻控制音樂播放器來解決按鈕問題。我正在用Python 3和Pocket Sphinx使用Raspberry Pi 3。因爲Pocket Sphinx不需要互聯網,所以我會使用它,因爲我的祖父無法訪問互聯網。Python 3和Pocket Sphinx
我的問題是如何採取「說」的值,例如:「播放按鈕」,並讓它播放波形文件「按鈕」?
這是我必須建立基本程序:
import speech_recognition as sr
import pygame
from pygame import mixer
mixer.init()
r = sr.Recognizer()
m = sr.Microphone()
Button = pygame.mixer.Sound('/home/pi/Downloads/button8.wav')
try:
print("A moment of silence, please...")
with m as source: r.adjust_for_ambient_noise(source)
print("Set minimum energy threshold to {}".format(r.energy_threshold))
while True:
print("Say something!")
with m as source: audio = r.listen(source)
print("Got it! Now to recognize it...")
try:
# recognize speech using Sphinx
value = r.recognize_sphinx(audio)
print("You said {}".format(value)) #uses unicode for strings and this is where I am stuck
pygame.mixer.Sound.play(Button)
pygame.mixer.music.stop()
except sr.UnknownValueError:
print("Oops! Didn't catch that")
except sr.RequestError as e:
print("Uh oh! Couldn't request results; {0}".format(e))
except KeyboardInterrupt:
pass
非常感謝你的幫助,你可以提供。請善待我,因爲我是初學者。
你什麼錯誤? –
它會打印什麼,但我不知道如何採取什麼說播放聲音。例如,我希望能夠說「播放按鈕」並讓它播放Pi上的Wave文件(Button.wav)。感謝您的幫助。 –