Create 32bit float wav file in python?

前端 未结 3 1851
感动是毒
感动是毒 2021-01-21 06:15

I want to create 32bit float WAV files in Python (2.x). While \"standard\" WAV files usually use int, many professional audio applications process (and save) audio data as float

3条回答
  •  长情又很酷
    2021-01-21 06:56

    This sounded like fun (see my handle), so I hammered out something. Maybe you can use it. If your Python script generates a monophonic waveform of numerical values that fall between [-1.0 .. 1.0], send that waveform in through sample_array and also specify sample_rate (e.g., 44100 or 48000). This will return to you an array that you can write to disk as a .wav file.

    I tested the resulting .wav output in Windows Media Player, Apple QuickTime Player, and VLC (all on Windows 7). They all played it.

    def float32_wav_file(sample_array, sample_rate):
      byte_count = (len(sample_array)) * 4  # 32-bit floats
      wav_file = ""
      # write the header
      wav_file += struct.pack('

提交回复
热议问题