Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jhj0517/Whisper-WebUI int…
Browse files Browse the repository at this point in the history
…o feature/add-tests
  • Loading branch information
jhj0517 committed Oct 1, 2024
2 parents e3dbb92 + 2d3dbbe commit 235513d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion modules/utils/youtube_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pytubefix import YouTube
import subprocess
import os


Expand All @@ -12,4 +13,21 @@ def get_ytmetas(link):


def get_ytaudio(ytdata: YouTube):
return ytdata.streams.get_audio_only().download(filename=os.path.join("modules", "yt_tmp.wav"))
# Somehow the audio is corrupted so need to convert to valid audio file.
# Fix for : https://github.com/jhj0517/Whisper-WebUI/issues/304

audio_path = ytdata.streams.get_audio_only().download(filename=os.path.join("modules", "yt_tmp.wav"))
temp_audio_path = os.path.join("modules", "yt_tmp_fixed.wav")

try:
subprocess.run([
'ffmpeg', '-y',
'-i', audio_path,
temp_audio_path
], check=True)

os.replace(temp_audio_path, audio_path)
return audio_path
except subprocess.CalledProcessError as e:
print(f"Error during ffmpeg conversion: {e}")
return None
3 changes: 3 additions & 0 deletions modules/whisper/whisper_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ def transcribe_youtube(self,
)
result_str = f"Done in {self.format_time(time_for_task)}! Subtitle file is in the outputs folder.\n\n{subtitle}"

if os.path.exists(audio):
os.remove(audio)

return [result_str, result_file_path]

except Exception as e:
Expand Down

0 comments on commit 235513d

Please sign in to comment.