How can we extend the following python code to transcribe more than one youtube url:…
Private research annotation
Sign in to add a private research label or note.
- User
How can we extend the following python code to transcribe more than one youtube url:
import os import yt_dlp import whisper
def download_audio_from_youtube(youtube_url, output_filename): """ Downloads the audio from a YouTube video and saves it to a file.
codeParameters: - youtube_url: str, the URL of the YouTube video. - output_filename: str, the output filename for the audio file. Returns: - audio_filename: str, the path to the downloaded audio file. """ ydl_opts = { 'format': 'bestaudio/best', 'outtmpl': output_filename, 'postprocessors': [ { 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', } ], 'quiet': True } with yt_dlp.YoutubeDL(ydl_opts) as ydl: print(f"Downloading audio from {youtube_url}...") ydl.download([youtube_url]) audio_filename = f"{output_filename}.mp3" if os.path.exists(audio_filename): print(f"Audio downloaded successfully: {audio_filename}") return audio_filename else: raise Exception("Failed to download audio.")def transcribe_audio(audio_filename, model_name="base"): """ Transcribes an audio file using OpenAI's Whisper model.
codeParameters: - audio_filename: str, the path to the audio file. - model_name: str, the name of the Whisper model to use. Returns: - transcription: str, the transcribed text. """ print(f"Loading Whisper model '{model_name}'...") model = whisper.load_model(model_name) print(f"Transcribing audio file {audio_filename}...") result = model.transcribe(audio_filename) transcription = result["text"] print("Transcription completed.") return transcriptiondef save_transcription(transcription, output_textfile): """ Saves the transcription to a text file.
- Assistant