1

Is there a way that I can use the python library sounddevice to write the output through my speakers to a file? For example if I were to play any sounds through my computer they would be written to a mp4/wav file.

| improve this question | |
1

This is a solution: (See comments)

import sounddevice as sd
from scipy.io.wavfile import write

fs = 44100  # Sample rate
seconds = 3  # Duration of recording
sd.default.device = 'digital output'  # Speakers full name here

myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
sd.wait()  # Wait until recording is finished
write('output.wav', fs, myrecording)  # Save as WAV file 

The above code was from: https://realpython.com/playing-and-recording-sound-python/#python-sounddevice_1 which is a full tutorial in sound in python and how to record and play sound.

| improve this answer | |
  • 1
    This is helps with writing to the wav file but it records sound through my microphone instead of the sounds made by my computer like if i played a video on it; the sound that would come out of my speakers. – TheFluffDragon9 Jun 26 at 14:33
  • @TheFluffDragon9 I edited my answer to change the input device to your speaker. If this does not work, I will delete my answer. – Eno Gerguri Jun 26 at 14:40
  • How do I find my speaker's full name? Is there a way to print a dveice list or somethin? Thanks for all of your help! Is that full stop after 'digital output' meant to be there btw? – TheFluffDragon9 Jun 26 at 15:13
  • @TheFluffDragon9 if you are using windows you can go to your sound settings and see the name of the output device, that is the one you want to enter. – Eno Gerguri Jun 26 at 15:15
  • Sorry to keep asking questions, but I just want to get this right. If this is what my sound settings say and I want the bottom speakers, what does my line of code look like? – TheFluffDragon9 Jun 26 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.