OK, I think I got, thank you for your patience!
My first error was here :
suffix = Path(audio_source).suffix
The good code is :
suffix = Path(audio_source.name).suffix
This one is OK, I was trying to get a suffix from my data instead of getting it from the filename.
My second error is in the open command, I’m just creating the file, not filling it with my audio content.
I think I’m going on a good way, but now this is CUDA throwing me an error
OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB. GPU 0 has a total capacity of 3.94 GiB of which 2.69 MiB is free. Including non-PyTorch memory, this process has 3.93 GiB memory in use. Of the allocated memory 3.86 GiB is allocated by PyTorch, and 12.81 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
Here is the “new” version of the code :
from pathlib import Path
from tempfile import NamedTemporaryFile
import streamlit as st
from speechbrain.inference.ASR import WhisperASR
import torch
st.title("Veuillez téléverser un fichier audio pour lancer la transcription")
col1 = st.columns(1) # disposition de l'affichage : une barre à gauche pour les boutons, une colonne sur le reste pour afficher la transcription
audio_source=st.sidebar.file_uploader(label="Choisir votre fichier", type=["wav","m4a","mp3","wma"]) # bouton de téléchargement
asr_model = WhisperASR.from_hparams(source="speechbrain/asr-whisper-medium-commonvoice-fr", savedir="pretrained_models/ ```
asr-whisper-medium-commonvoice-fr
```", run_opts={"device":"cuda"})
if audio_source is not None: # on vérifie qu'un fichier a été téléversé
st.write("Transcription en cours ...")
predicted_text = "None"
suffix = Path(audio_source.name).suffix
with NamedTemporaryFile(suffix=suffix) as temp_file:
temp_file.write(audio_source.getvalue())
temp_file.seek(0)
predicted_text = asr_model.transcribe_file(temp_file.name)
st.write("Fichier transcrit :")
st.write(predicted_text)
st.sidebar.download_button(label="Télécharger la transcription", data=predicted_text, file_name="transcript.txt",mime="text/plain")
I am surprised because the model’s size seems to be +/- 2.9 to 3.06GB, wouldn’t it run on a 4GB graphics card?
Or should I try to run the script on the CPU by removing , run_opts={“device”:“cuda”} ?