Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

audio - Is there anyway I can record the sound that comes from my computer and save it to a wav or mp3 file in python?

I am trying to write a python program where it can capture everything i am doing on the computer and project it wherever I want. I know there are programs i can download but i want to try and make it myself. I have already made a screen recorder but i still need the audio. The language im using is python. Any help is appreciated.

question from:https://stackoverflow.com/questions/65923251/is-there-anyway-i-can-record-the-sound-that-comes-from-my-computer-and-save-it-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

https://realpython.com/playing-and-recording-sound-python/#python-sounddevice_1

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 

just change the device to your speakers and you should be good to go


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...