Created
October 16, 2018 11:01
-
-
Save Honghe/12a1d6ffc5cc580646aeef55cb306ded to your computer and use it in GitHub Desktop.
Python wav sound convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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