1

I want to create Flask Web Application that can hear sound from Server Microphone and download the last sound by clicking button.

For now, I can read and get sound level and recording the sound using this script

import os, sys, queue, tempfile

import sounddevice as sd
import soundfile as sf
import numpy as np

print("sd.query_devices()")
print(sd.query_devices())

q = queue.Queue()
sd_level = 0

def callback(indata, frames, time, status):
    if status:
        print(status, file=sys.stderr)
    q.put(indata.copy())

try:
    device_info = sd.query_devices(None, 'input')
    samplerate = int(device_info['default_samplerate'])
    filename = tempfile.mktemp(prefix='test_mic_recorder_',
                                suffix='.wav', dir='')

    with sf.SoundFile(filename, mode='x', samplerate=samplerate,
                      channels=1, subtype=None) as file:
        with sd.InputStream(samplerate=samplerate, device=None,
                            channels=1, callback=callback):
            while True:
                data_sound = q.get()
                sd_level = np.linalg.norm(data_sound)*100
                print ("|" * int(sd_level))
                file.write(data_sound)
except KeyboardInterrupt:
    print('\nRecording finished: ' + repr(filename))

is anyone know how to send microphone sound over Python-Flask ??

Zenaki
  • 11
  • 1
  • Have you seen this post [Playing a wavefile from the html using flask framework?](https://stackoverflow.com/questions/17359741/playing-a-wavefile-from-the-html-using-flask-framework) – Sid Kwakkel Feb 26 '21 at 05:08
  • I want to stream my server microphone over flask web – Zenaki Feb 26 '21 at 08:28

0 Answers0