mirror of
https://github.com/chidiwilliams/buzz.git
synced 2026-03-15 07:05:48 +01:00
Adding path to ffmpeg for installed app on windows (#942)
This commit is contained in:
parent
724fdea33f
commit
03e882eebf
1 changed files with 23 additions and 9 deletions
32
buzz/transcriber/file_transcriber.py
Normal file → Executable file
32
buzz/transcriber/file_transcriber.py
Normal file → Executable file
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import shutil
|
||||
import tempfile
|
||||
from abc import abstractmethod
|
||||
|
|
@ -9,6 +10,7 @@ from PyQt6.QtCore import QObject, pyqtSignal, pyqtSlot
|
|||
from yt_dlp import YoutubeDL
|
||||
from yt_dlp.utils import DownloadError
|
||||
|
||||
from buzz.whisper_audio import SAMPLE_RATE
|
||||
from buzz.transcriber.transcriber import (
|
||||
FileTranscriptionTask,
|
||||
get_output_file_path,
|
||||
|
|
@ -32,31 +34,43 @@ class FileTranscriber(QObject):
|
|||
def run(self):
|
||||
if self.transcription_task.source == FileTranscriptionTask.Source.URL_IMPORT:
|
||||
temp_output_path = tempfile.mktemp()
|
||||
wav_file = temp_output_path + ".wav"
|
||||
|
||||
ydl = YoutubeDL(
|
||||
{
|
||||
"format": "wav/bestaudio/best",
|
||||
"progress_hooks": [self.on_download_progress],
|
||||
"outtmpl": temp_output_path,
|
||||
"logger": logging.getLogger(),
|
||||
"postprocessors": [
|
||||
{
|
||||
"key": "FFmpegExtractAudio",
|
||||
"preferredcodec": "wav",
|
||||
}
|
||||
],
|
||||
"logger": logging.getLogger()
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
logging.debug(f"Downloading audio file from URL: {self.transcription_task.url}")
|
||||
ydl.download([self.transcription_task.url])
|
||||
except DownloadError as exc:
|
||||
except Exception as exc:
|
||||
logging.debug(f"Error downloading audio: {exc.msg}")
|
||||
self.error.emit(exc.msg)
|
||||
return
|
||||
|
||||
self.transcription_task.file_path = temp_output_path + ".wav"
|
||||
cmd = [
|
||||
"ffmpeg",
|
||||
"-nostdin",
|
||||
"-threads", "0",
|
||||
"-f", "s16le",
|
||||
"-ac", "1",
|
||||
"-acodec", "pcm_s16le",
|
||||
"-ar", str(SAMPLE_RATE),
|
||||
"-loglevel", "error",
|
||||
"-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"))
|
||||
|
||||
self.transcription_task.file_path = wav_file
|
||||
logging.debug(f"Downloaded audio to file: {self.transcription_task.file_path}")
|
||||
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue