凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

python 录音,WAV转MP3

mp3
2019-08-29 python 1459

录音功能 ,只录音系统的声音

import sounddevice as sd
from scipy.io import wavfile
# fs = 44100  # Hz
# length = 15  # s
recording = sd.rec(frames=fs * length, samplerate=fs, blocking=True, channels=1)

wavfile.write(file, fs, recording)


WAV转MP3 需要安装ffmpeg 


from pydub import AudioSegment
import os
os.environ["PATH"] = os.environ["PATH"] + ";" + os.path.dirname(os.path.realpath(__file__)) #修改系统临时变量,把ffmpeg带回家
file = r'C:/Users/Administrator/Desktop/system1.wav'

song = AudioSegment.from_wav(file)
mp3file = os.path.splitext(file)[0] + ".mp3"
print(mp3file)
song.export(mp3file, format="mp3", bitrate="192k")








文章评论

0条评论