0

I am working on a genre identification project and trying to utilize sounddevice to input the audio. I have attempted using sample code from their website as well as stack overflow but am unable to get the codes to run without finishing with exit code 0. I've seen where people have said this is a device identification issue but even with declaring the input/output im am still not recording any audio. Here is the code below

import sounddevice as sd
from scipy.io.wavfile import write
sd.default.device = 1,3;
fs = 44100 #sample rate
duration = 5 

myrecording = sd.rec(int(duration*fs), samplerate=fs, channels=2)
sd.wait()
write('output.wav,fs myrecording)

1 Answers1

0

A few things:

  1. Are you certain your default device should be specified as 1,3?, these may be the incorrect input/output channels - you can print the sd.DeviceList to find out more info about your actual devices.

  2. When you call sd.rec(..., channels=2) are you sure that your input device has 2 channels? This isn't always the case (i.e. a normal microphone is a single channel unless you are using some sort of audio interface) tip -> you can use query_channels() to found out how many channels your device supports

  3. I presume that the write('output.wav,fs myrecording) was just a typo? You should make sure its write('output.wav',fs myrecording)

Personally in my experience (and preference) I always had more success with PyAudio and would usually recommend it for desktop audio I/O with Python!

WoodyDev
  • 1,386
  • 1
  • 9
  • 19