0
私は、端末で動作するときに動作する以下のスクリプトを持っています:DjangoでPython SpeechRecognitionを使用することはできますか?
すべては、マイク音声をテキストに変換しますか?
ボタンを押した後にこの作業をDjangoで行うことは可能でしょうか?
ビュー:
import speech_recognition as sr
# Create your views here.
def index(request):
return render(request, 'app/index.html')
def text(request):
r = sr.Recognizer()
with sr.Microphone() as source:
#print("Say something!")
audio = r.listen(source)
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
speech = r.recognize_google(audio)
except sr.UnknownValueError:
speech = "Google Speech Recognition could not understand audio"
except sr.RequestError as e:
speech = "Could not request results from Google Speech Recognition service; {0}".format(e)
return render(request, 'app/text', {'speech': speech})
テンプレート:よう 何か
<form action="/text/" method="post">
<input type="button" value="Start listening" />
</form>
これは可能ですか?私は閉じているのか、まったくないのですか?
DjangoがWebフォームをロードしているマシンと同じマシンで実行されている場合は、動作する可能性があります(確かにそうするべきではありませんが)。一方、Djangoバックエンドを使用してデータをGoogle APIに転送するようにユーザーに指示したい場合は、クライアント側でオーディオを収集する必要があります。 – zwer