I want to press a button in an html-template
<form action="{% url 'speech2text' %}" class="card-text" method="POST">
{% csrf_token %}
<button class="btn btn-primary btn-sm" type="submit">Start</button>
</form>
<p> Sie haben das folgende gesagt: </p>
<p> {{ speech_text }} </p>
by pressing the button, the code in the following view shall be executed and send back the result into the template:
def speech2textView(request):
if request.method == "POST":
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
text = r.recognize_google(audio, language="de-DE")
args = {'speech_text': text}
return render(request, 'speech2text.html', args)
Whats wrong here? many thanks for your help.
print()
to check ifrequest.method
have value"POST"
and iftext
gets any string from google. You should also check if you don't get any error when run it. And I assume that you run django on local computer because django on server don't have access to your local microphone. – furas