Skip to content

Commit

Permalink
Added support for a-law audios to be able to use audios from Barrayar.
Browse files Browse the repository at this point in the history
  • Loading branch information
anikocharyan committed Apr 10, 2024
1 parent 6e09030 commit 6f28308
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cli-client/helpers/audio_importer.py
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)

0 comments on commit 6f28308

Please sign in to comment.