Skip to content

Commit

Permalink
Will not check process return code, but error (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Oct 12, 2024
1 parent 03e882e commit d5d95a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
12 changes: 6 additions & 6 deletions buzz/transcriber/file_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ def run(self):
"-ac", "1",
"-acodec", "pcm_s16le",
"-ar", str(SAMPLE_RATE),
"-loglevel", "error",
"-loglevel", "panic",
"-i", temp_output_path, wav_file]

try:
subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as exc:
logging.debug(f"Error processing downloaded audio: {exc.msg}")
raise Exception(exc.stderr.decode("utf-8"))
result = subprocess.run(cmd, capture_output=True)

if len(result.stderr):
logging.warning(f"Error processing downloaded audio. Error: {result.stderr.decode()}")
raise Exception(f"Error processing downloaded audio: {result.stderr.decode()}")

self.transcription_task.file_path = wav_file
logging.debug(f"Downloaded audio to file: {self.transcription_task.file_path}")
Expand Down
20 changes: 14 additions & 6 deletions buzz/transcriber/openai_whisper_api_file_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ def transcribe(self) -> List[Segment]:

mp3_file = tempfile.mktemp() + ".mp3"

cmd = ["ffmpeg", "-i", self.transcription_task.file_path, mp3_file]
cmd = [
"ffmpeg",
"-threads", "0",
"-loglevel", "panic",
"-i", self.transcription_task.file_path, mp3_file
]

try:
subprocess.run(cmd, capture_output=True, check=True)
except subprocess.CalledProcessError as exc:
logging.exception("")
raise Exception(exc.stderr.decode("utf-8"))
result = subprocess.run(cmd, capture_output=True)

if result.returncode != 0:
logging.warning(f"FFMPEG audio load warning. Process return code was not zero: {result.returncode}")

if len(result.stderr):
logging.warning(f"FFMPEG audio load error. Error: {result.stderr.decode()}")
raise Exception(f"FFMPEG Failed to load audio: {result.stderr.decode()}")

# fmt: off
cmd = [
Expand Down
2 changes: 1 addition & 1 deletion buzz/whisper_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def load_audio(file: str, sr: int = SAMPLE_RATE):
"-ac", "1",
"-acodec", "pcm_s16le",
"-ar", str(sr),
"-loglevel", "error",
"-loglevel", "panic",
"-"
]
# fmt: on
Expand Down

0 comments on commit d5d95a5

Please sign in to comment.