gpt4 book ai didi

python - 是否可以在 Django 上使用 Python SpeechRecognition?

转载 作者:太空宇宙 更新时间:2023-11-04 02:56:07 32 4
gpt4 key购买 nike

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

所做的只是将麦克风语音转换为文本。

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 上进行这项工作?像这样的东西:

查看:

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 无法访问用户的计算机,因此如果您尝试从麦克风录音,您将使用服务器的麦克风(如果有的话)。

您需要record using JS/HTML5然后将数据发送到 django 以使用 AJAX 进行处理。您甚至可以流式传输它,但这可能不值得付出努力。

关于python - 是否可以在 Django 上使用 Python SpeechRecognition?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42311555/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com