【发布时间】:2020-09-11 08:08:35
【问题描述】:
我正在尝试从锯齿波中播放声音。我在 Python 中创建了波形并能够将其保存为 WAV 文件,但是当我尝试播放它时,它说文件无法播放,因为文件类型不受支持、文件扩展名不正确或文件已损坏。我使用了这个人的教程 (https://thehackerdiary.wordpress.com/2017/06/09/it-is-ridiculously-easy-to-generate-any-audio-signal-using-python/),他们通过在 Audacity 中将原始波形从 16 位编码到 8 位来解决这个问题。仅使用 Python 怎么能做到这一点?
import soundfile
data, samplerate = soundfile.read('sawtooth_100_hz.wav')
soundfile.write('sawtooth_100_hz_8bit.wav', data, samplerate, subtype='PCM_S8')
^^ 我试过这个并得到以下错误: ValueError: Invalid combination of format, subtype and endian
【问题讨论】: