Heey guys! I am trying to open a channel for recording something with mycrophone in google colab but i got a error.
OSError: [Errno -9996] Invalid input device (no default output device)
If i run the code in Spyder, in spyder works! Any ideea how to enable google colabs to ,,see " my default microphone? The code is:
import pyaudio
import wave
from array import array
import struct
import time
# Initialize variables
RATE = 24414
CHUNK = 512
RECORD_SECONDS = 7.1
FORMAT = pyaudio.paInt32
CHANNELS = 1
WAVE_OUTPUT_FILE = "/content/drive/My Drive/Colab Notebooks/output.wav"
# Open an input channel
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
# Initialize a non-silent signals array to state "True" in the first 'while' iteration.
data = array('h', np.random.randint(size = 512, low = 0, high = 500))
# SESSION START
print("** session started")
total_predictions = [] # A list for all predictions in the session.
tic = time.perf_counter()
while is_silent(data) == False:
print("* recording...")
frames = []
data = np.nan # Reset 'data' variable.
timesteps = int(RATE / CHUNK * RECORD_SECONDS) # => 339
# Insert frames to 'output.wav'.
for i in range(0, timesteps):
data = array('l', stream.read(CHUNK))
frames.append(data)
wf = wave.open(WAVE_OUTPUT_FILE, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
print("* done recording")