| import wave |
| import os |
|
|
|
|
| basePath = os.path.expanduser("~/Desktop/") |
|
|
|
|
| def convert_pcm_to_wav(): |
| |
| pcm_file = basePath + 'output.pcm' |
| wav_file = 'pcmconverted.wav' |
| sample_rate = 16000 |
| channels = 1 |
| sample_width = 2 |
|
|
| |
| with open(pcm_file, 'rb') as pcmfile: |
| pcm_data = pcmfile.read() |
|
|
| with wave.open(wav_file, 'wb') as wavfile: |
| wavfile.setnchannels(channels) |
| wavfile.setsampwidth(sample_width) |
| wavfile.setframerate(sample_rate) |
| wavfile.writeframes(pcm_data) |
|
|
| convert_pcm_to_wav() |
|
|
| |
|
|
| |
|
|
|
|
|
|
| print(f"Converted {pcm_file} to {wav_file}") |
|
|