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.
-
1It does not; In that, question, they are trying to write tones based on frequencies and amplitudes. In my question, I would like to record any sounds that my computer makes and write them to a file. Like if I were to play a song it would all be recorded to a file. I appreciate that I'm not the best at wording questions. Thanks for replying so fast though @EnoGerguri – TheFluffDragon9 Jun 26 at 14:08
-
See stackoverflow.com/q/58780206, github.com/spatialaudio/python-sounddevice/issues/129, github.com/spatialaudio/python-sounddevice/issues/244. – Matthias Jun 28 at 8:34
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.
-
1This 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