From 825418f86acfb2314a3df5001074647beb38556a Mon Sep 17 00:00:00 2001 From: Francois Pelletier Date: Sun, 10 Mar 2024 00:55:20 +0000 Subject: [PATCH] Actualiser whisper.py Signed-off-by: Francois Pelletier --- whisper.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/whisper.py b/whisper.py index 938b99c..bb5fc0a 100644 --- a/whisper.py +++ b/whisper.py @@ -1,4 +1,6 @@ # %% Utilisation de Whisper pour la transcription de podcasts en français +from pathlib import Path + import numpy as np import torch import torchaudio @@ -11,8 +13,11 @@ from transformers import ( ) # %% File paths + audio_paths = ["METTRE LES LIENS DES FICHIERS MP3 OU WAV ICI"] +audio_dir = "data" + # %% load PyTorch device = "cuda:0" if torch.cuda.is_available() else "cpu" torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32 @@ -50,10 +55,10 @@ pipe = pipeline( # %% Transcript function -def transcript(audio_path): +def transcript(audio_dir, audio_path): # Load audio model_sr = 16000 - speech, sr = torchaudio.load(audio_path) + speech, sr = torchaudio.load(Path(audio_dir) / audio_path) speech_16000 = torchaudio.functional.resample(speech, orig_freq=sr, new_freq=model_sr) speech_16000 = speech_16000.squeeze() @@ -69,4 +74,4 @@ def transcript(audio_path): # %% Transcription loop for audio_path in tqdm.tqdm(audio_paths): - transcript(audio_path) + transcript(audio_dir, audio_path)