-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for a-law audios to be able to use audios from Barrayar.
- Loading branch information
1 parent
6e09030
commit 6f28308
Showing
1 changed file
with
15 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
import os | ||
import subprocess | ||
import wave | ||
|
||
def preprocess_audio_file_to_pcm(audio_file: str): | ||
tmp_audio_file = "./" + os.path.basename(audio_file) + "_tmp.wav" | ||
command = "sox " + audio_file + " -e signed-integer " + tmp_audio_file | ||
subprocess.run(command.split()) | ||
return tmp_audio_file | ||
|
||
|
||
def remove_pcm_audio_file(audio_file: str): | ||
os.remove(audio_file) | ||
|
||
|
||
class AudioImporter: | ||
def __init__(self, audio_file: str): | ||
with open(audio_file, "rb") as wav_file: | ||
tmp_audio_file = preprocess_audio_file_to_pcm(audio_file) | ||
with open(tmp_audio_file, "rb") as wav_file: | ||
wav_data = wave.open(wav_file) | ||
self.sample_rate = wav_data.getframerate() | ||
self.audio = wav_data.readframes(wav_data.getnframes()) | ||
wav_data.close() | ||
|
||
remove_pcm_audio_file(tmp_audio_file) |