我正在开发一个带有烧瓶和语音识别的web应用程序,用于音频输入、处理和在屏幕上显示输出。这个职位帮助我组织音频文件的输入,下面是我的烧瓶代码:
list_msg = []
@app.route("/process_wav", methods=['GET', 'POST'])
def process_wav():
if request.method == 'POST':
audio_file = request.form.get("audio-recording")
dir = 'audio/'+str(audio_file)
msg = Mensaje(dir) # this is a custom class I created for storing and processing the audio
list_msg.append((dir, msg.sentence, msg.word_counter))
return render_template("process_wav.html", list_msg=list_msg)我的HTML代码:
{% block flask %}
<h1>Prototype</h1>
<section>
<form action="" method="POST" class="form-input">
<div class="form-input">
<label for="audio-recording">Audio file (.wav)</label>
<input name="audio-recording" type="file" accept="audio/*" id="audio-recording" >
<button class="form-submit" type="submit" id="entry">Submit</button>
</div>
</form>
</section>
{% for msg in list_msg %}
<section class="form-output" id="output">
<h3>{{ msg[0] }}</h3>
<p>Result: "{{ msg[1] }}"</p>
<p>Counter: {{ msg[2] }}</p>
</section>
{% endfor %}
{% endblock flask %}但我发现有必要通过麦克风直接输入音频(并以与.wav音频文件相同的方式处理音频文件)。因此,我的问题是:如何通过麦克风以HTML格式将音频输入到网页,以便将其传递给烧瓶和python,以便进行处理,然后显示输出?
作为Flask和HTML的新手,我发现很难找到好的参考资料,尽管我发现HTML本身并不提供这种参考。欢迎任何建议。
发布于 2021-04-08 18:40:01
功能流音频现场使用烧瓶。实际上我没有得到你真正想做的事。但是这样你就可以在烧瓶里播放音频了。
@app.route("/fetchAudio",methods=["GET"])
def fetch_audio():
def generate():
with open("SampleAudio.mp3", "rb") as audio: # your audio file path here
audio_data = audio.read(1024)
while audio_data:
yield audio_data
audio_data = audio.read(1024)
return Response(generate(), mimetype="audio/x-wav") # header for audio type希望这能帮上忙。链接
https://stackoverflow.com/questions/67009699
复制相似问题