如何将WAV音频文件格式(深度)转换为8位格式?

问题描述 投票:1回答:1

我正在使用记录声音的python gui,然后需要将wav文件的格式设置为8位。我该怎么办?

我尝试使用Playsound。但是我可以做的最小更改是16位。有什么想法吗?我是音频分析和python编程的新手。

def startrecording(self): self.p = pyaudio.PyAudio() self.stream = self.p.open(format=Pyaudio.PaInt16, channels=2, rate=44100, frames_per_buffer=1024, input=True) self.isrecording = True print('Recording') t = threading.Thread(target=self.record) t.start()

这是我使用的录音功能。我试图直接用PaInt8更改PaInt16,但是录音效果不好。只是有声音

python audio pyaudio wave playsound
1个回答
0
投票

您可以像这样使用soundfile.write()

import librosa  # just to demo, not necessary, as you already have the data
import soundfile

# read some wave file, so that y is the date and sr the sample rate
y, sr = librosa.load('some.wav')

# write to a new wave file with sample rate sr and format 'unsigned 8bit'
soundfile.write('your.wav', y, sr, subtype='PCM_U8')

要获取某种格式的可用子类型,请使用:

>>> soundfile.available_subtypes('WAV')
{'PCM_16': 'Signed 16 bit PCM', 'PCM_24': 'Signed 24 bit PCM', 'PCM_32': 'Signed 32 bit PCM', 'PCM_U8': 'Unsigned 8 bit PCM', 'FLOAT': '32 bit float', 'DOUBLE': '64 bit float', 'ULAW': 'U-Law', 'ALAW': 'A-Law', 'IMA_ADPCM': 'IMA ADPCM', 'MS_ADPCM': 'Microsoft ADPCM', 'GSM610': 'GSM 6.10', 'G721_32': '32kbs G721 ADPCM'}
© www.soinside.com 2019 - 2024. All rights reserved.