5

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?

Sanskar Jethi
  • 544
  • 5
  • 17
  • I believe the functionality you are after is implemented by custom audio drivers. What operating system does it need to work on? – GordonAitchJay Feb 16 '21 at 11:44
  • The operating system it needs to work on is Windows. – ahmedquran12 Feb 16 '21 at 21:38
  • @GordonAitchJay , I use osx and linux . I believe the audio drivers are not causing much issue here. I am unable to create a stream of audio. I don't want to save it as an mp3 file and then play it. – Sanskar Jethi Feb 17 '21 at 15:21

2 Answers2

1

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

Bob
  • 13,867
  • 1
  • 5
  • 27
  • 3
    I think what Sanskar Jethi wants is to read in from a real microphone, process the signal, then output it to a virtual microphone. That virtual microphone will then be selected as the microphone in Zoom/Google Hangouts. – GordonAitchJay Feb 19 '21 at 09:26
-1

Required Module: pyaudio

install it through pip:

pip install pyaudio

NOTE: I've faced issues while trying to install pyaudio module in python 3.8 version but have read a lot of articles that with python 3.5 you won't face any issues.

If you want to save the audio recorded through microphone you can follow https://gist.github.com/mabdrabo/8678538 (to have .mp3 extension modify the variable WAVE_OUTPUT_FILENAME in the code to WAVE_OUTPUT_FILENAME = "file.mp3")

You can also use the SpeechRecognition module. follow this link https://www.youtube.com/watch?v=x8xjj6cR9Nc where he has created a python speech assistance (like google assistance) in a 30min video from scratch and github link to the code in video description.

  • How do I play it through a certain microphone – ahmedquran12 Feb 15 '21 at 21:29
  • 2
    Using pyaudio will save it to an mp3 file. I want to create a constant stream of audio source that can be used as an input source – Sanskar Jethi Feb 16 '21 at 05:42
  • Can you explain what do you want exactly? Audio can't be played through the microphone since microphone is an input device. Audio can be played only by speaker as it is a output device. Is your requirement, to record audio continuously till you can trigger an event to stop the recording? – Sambit Kumar Feb 16 '21 at 11:43
  • 2
    To play constant audio through a virtual microphone (look up VB-Cable) – ahmedquran12 Feb 16 '21 at 21:23