私はオーディオ制御の音楽プレーヤーをプログラミングすることでボタンに問題がある祖父のためのシンプルな音楽プレーヤーを作成しようとしています。私は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
あなたが提供することができます任意の助けをありがとうございました。私は初心者なので、親切にしてください。
あなたはどのようなエラーが出るのですか? –
それは何が言われているかを印刷しますが、私はどのように音を再生すると言われているかわからない。たとえば、 "Play Button"と言うと、Pi(Button.wav)でWaveファイルを再生できるようにしたいと考えています。ご協力ありがとうございました。 –