Python 3 和袖珍狮身人面像
Python 3 and Pocket Sphinx
我正在尝试通过对音频控制的音乐播放器进行编程,为不习惯使用按钮的祖父创建一个简单的音乐播放器。我正在使用 Raspberry Pi 3 和 Python 3 以及 Pocket Sphinx。因为 Pocket Sphinx 不需要互联网,所以我会使用它,因为我的祖父无法访问互联网。
我的问题是如何获取 "said" 的值,例如:"Play Button" 并让它播放波形文件 "Button"?
这是我必须构建的基本程序:
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
非常感谢您提供的任何帮助。请善待,因为我是初学者。
尝试将其与 'play button' 进行比较:
# recognize speech using Sphinx
value = r.recognize_sphinx(audio)
print("You said {}".format(value))
if value.lower() == 'play button':
pygame.mixer.Sound.play(Button)
pygame.mixer.music.stop()
我正在尝试通过对音频控制的音乐播放器进行编程,为不习惯使用按钮的祖父创建一个简单的音乐播放器。我正在使用 Raspberry Pi 3 和 Python 3 以及 Pocket Sphinx。因为 Pocket Sphinx 不需要互联网,所以我会使用它,因为我的祖父无法访问互联网。
我的问题是如何获取 "said" 的值,例如:"Play Button" 并让它播放波形文件 "Button"?
这是我必须构建的基本程序:
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
非常感谢您提供的任何帮助。请善待,因为我是初学者。
尝试将其与 'play button' 进行比较:
# recognize speech using Sphinx
value = r.recognize_sphinx(audio)
print("You said {}".format(value))
if value.lower() == 'play button':
pygame.mixer.Sound.play(Button)
pygame.mixer.music.stop()