可以在Django上使用Python SpeechRecognition吗?

可以在Django上使用Python SpeechRecognition吗?,python,django,python-2.7,speech-recognition,Python,Django,Python 2.7,Speech Recognition,在终端中运行时,我有以下脚本: 只需将麦克风语音转换为文本即可 import speech_recognition as sr # obtain audio from microphone r = sr.Recognizer() with sr.Microphone() as source: print("Say something!") audio = r.listen(source) try: # for testing purposes, we're just

在终端中运行时,我有以下脚本:

只需将麦克风语音转换为文本即可

import speech_recognition as sr

# obtain audio from microphone
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)`
    print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))
在按下按钮之后,是否有可能在Django上进行此项工作? 比如:

视图:

模板:

<form action="/text/" method="post">
    <input type="button" value="Start listening" />
</form>


这可能吗?我是否已关闭?

Django无法访问用户的计算机,因此如果您尝试使用麦克风录制,您将使用服务器的麦克风(如果有)


您需要将数据发送到django,然后使用AJAX进行处理。您甚至可以对其进行流式处理,但可能不值得这样做。

如果Django在加载web表单的同一台机器上运行,那么它可能会工作(尽管肯定不是应该这样做)。另一方面,如果你想让用户使用你的Django后端将数据转发到Google API,不-你必须在客户端收集音频。你找到解决方案了吗?在桌面应用程序上可以吗?
<form action="/text/" method="post">
    <input type="button" value="Start listening" />
</form>