python flask trial
вот мой код, когда запускаю с телефона воспроизведения аудио потока, каждые несколько секунд слышу то ли trial, то ли tryel, вообще помогите пожалуйста, как исправить это?
main.py
from flask import Flask, Response, render_template
import pyaudio
app = Flask(__name__) # Исправлено на __name__
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 1
audio1 = pyaudio.PyAudio()
def genHeader(sampleRate, bitsPerSample, channels):
datasize = 2000 * 10**6
o = bytes("RIFF", 'ascii') # (4byte) Marks file as RIFF
o += (datasize + 36).to_bytes(4, 'little') # (4byte) File size in bytes excluding this and RIFF marker
o += bytes("WAVE", 'ascii') # (4byte) File type
o += bytes("fmt ", 'ascii') # (4byte) Format Chunk Marker
o += (16).to_bytes(4, 'little') # (4byte) Length of above format data
o += (1).to_bytes(2, 'little') # (2byte) Format type (1 - PCM)
o += (channels).to_bytes(2, 'little') # (2byte)
o += (sampleRate).to_bytes(4, 'little') # (4byte)
o += (sampleRate * channels * bitsPerSample // 8).to_bytes(4, 'little') # (4byte)
o += (channels * bitsPerSample // 8).to_bytes(2, 'little') # (2byte)
o += (bitsPerSample).to_bytes(2, 'little') # (2byte)
o += bytes("data", 'ascii') # (4byte) Data Chunk Marker
o += (datasize).to_bytes(4, 'little') # (4byte) Data size in bytes
return o
@app.route('/audio')
def audio():
def sound():
sampleRate = 44100
bitsPerSample = 16
channels = 2
wav_header = genHeader(sampleRate, bitsPerSample, channels)
stream = audio1.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True, input_device_index=1,
frames_per_buffer=CHUNK)
print("recording...")
first_run = True
try:
while True:
if first_run:
data = wav_header + stream.read(CHUNK)
first_run = False
else:
data = stream.read(CHUNK)
yield data
except GeneratorExit:
print("Stream closed.")
finally:
stream.stop_stream()
stream.close()
return Response(sound(), mimetype="audio/wav")
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__": # Исправлено на __name__ == "__main__"
app.run(host='0.0.0.0', debug=False, threaded=True, port=5000)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<audio controls>
<source src="{{ url_for('audio') }}" type="audio/wav">
Your browser does not support the audio element.
</audio>
</body>
</html>