Skip to content

Instantly share code, notes, and snippets.

@Honghe
Created October 16, 2018 11:01
Show Gist options
  • Save Honghe/12a1d6ffc5cc580646aeef55cb306ded to your computer and use it in GitHub Desktop.
Save Honghe/12a1d6ffc5cc580646aeef55cb306ded to your computer and use it in GitHub Desktop.
Python wav sound convert
with open("audioData_original.wav", 'wb') as of:
of.write(message['audio'])
audioFile = wave.open("audioData_original.wav", 'r')
n_frames = audioFile.getnframes()
audioData = audioFile.readframes(n_frames)
originalRate = audioFile.getframerate()
af = wave.open('audioData.wav', 'w')
af.setnchannels(1)
af.setparams((1, 2, 16000, 0, 'NONE', 'Uncompressed'))
converted = audioop.ratecv(audioData, 2, 1, originalRate, 16000, None)
af.writeframes(converted[0])
af.close()
audioFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment