У меня есть сценарий python, который записывает звук и преобразует его в текст. Я хочу отобразить этот текст на веб-странице, используя flask бэкэнд
python скрипт
def speech():
r = sr.Recognizer()
text = ""
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("Please say something")
audio = r.listen(source)
print("Recognizing Now .... ")
# recognize speech using google
try:
text = r.recognize_google(audio)
except Exception as e:
print("Error : " + str(e))
return text
Flask код
@app.route('/')
def predict():
text = spt.speech()
return render_template('index.html', prediction_text = '{}'.format(text) )
HTML Код
<form action="{{ url_for('predict')}}">
<button type="submit" class="btn btn-primary btn-block btn-large">Predict</button>
</form>
<textarea rows = "5" cols= "60" name="description">{{ prediction_text }}
</textarea>