1 year ago
#364749
AEDEDD
Use the mobile phone's microphone instead of the computer's microphone
I am trying to record audio in a file and it is already working in the computer but when I connect my mobile phone to the localhost to be able to manipulate the web and check how is it seen, I realised that when I try to record an audio even if I am connected from my mobile phone it is listening to the computer's microphone instead of the phone's microphone. Is there any way to solve this?
def generate():
chunk = 1024 # Record in chunks of 1024 samples
sample_format = pyaudio.paInt16 # 16 bits per sample
channels = 1
fs = 44100 # Record at 44100 samples per second
seconds = 4
filename = "/Users/enekoiza/Desktop/easy-peasy/test2.wav"
p = pyaudio.PyAudio() # Create an interface to PortAudio
print('Recording')
stream = p.open(format=sample_format,
channels=channels,
rate=fs,
frames_per_buffer=chunk,
input=True)
frames = [] # Initialize array to store frames
# Store data in chunks for 3 seconds
for i in range(0, int(fs / chunk * seconds)):
data = stream.read(chunk)
frames.append(data)
# Stop and close the stream
stream.stop_stream()
stream.close()
# Terminate the PortAudio interface
p.terminate()
print('Finished recording')
# Save the recorded data as a WAV file
wf = wave.open(filename, 'w')
wf.setnchannels(channels)
wf.setsampwidth(p.get_sample_size(sample_format))
wf.setframerate(fs)
wf.writeframes(b''.join(frames))
wf.close()
python
pyaudio
microphone
0 Answers
Your Answer