Actualiser whisper.py
Signed-off-by: Francois Pelletier <francois@noreply.git.jevalide.ca>
This commit is contained in:
parent
82c3cbd232
commit
825418f86a
1 changed files with 8 additions and 3 deletions
11
whisper.py
11
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)
|
||||
|
|
Loading…
Reference in a new issue