Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way using python to input a mp3/audio file to a microphone input?

My main purpose is to change the pitch of the my voice and then input it to a voice room/voice call say like a zoom call or a hangouts meeting without playing it back to me.

I found 2 questions on a similar topic: 1. Playing mp3 file through microphone with python 2. How to play MP3 files into the microphone input jQuery

But these ones do not answer the question appropriately.

Something similar to this: https://github.com/jremmons/pyfakewebcam/blob/master/pyfakewebcam/pyfakewebcam.py

but for microphones?

like image 431
Sanskar Jethi Avatar asked Nov 07 '22 08:11

Sanskar Jethi


1 Answers

You can use sounddevice, just tested it on Windows 10

you can create a stream and read data while as it records, naturally you will have a latency proportional to the size of the chunk you read.

This example records 6.4 seconds of audio at 16kHz. After finished you call the method stop. Each chunk in this example has 1024 samples corresponding to 64 milliseconds.

micStream = sd.InputStream(samplerate=16000, blocksize=1024, channels=1, dtype='float32')
micStream.start();
CHUNK_SIZE = 1024
NCHUNKS = 100
wavData = np.zeros(CHUNK_SIZE*NCHUNKS)
for i in range(0, NCHUNKS):
    chunkData, overflowed = micStream.read(CHUNK_SIZE);
    wavData[i*chunk:(i+1)*chunk] = np.mean(chunkData, axis=1) # ensure to be mono
micStream.stop()
plt.plot(wavData)

Recorded wave

like image 98
Bob Avatar answered Nov 14 '22 22:11

Bob