Error 'tuple.index(x): x not in tuple' in 'model.transcribe' from wishper in python

419 views Asked by At

I am trying to make a program that, among other things, is capable of transcribing audio files selected by the user as well as voluntarily choosing the language in which the specific audio is in.

But I am encountering the following problem:

ERROR:root:Error at division
Traceback (most recent call last):
  File "C:\Users\...\AppData\Local\Temp\ipykernel_27364\1513539390.py", line 136, in transcribir
    result = model.transcribe(audio, language=f"{actual_language}", fp16=False, verbose=True)
  File "C:\Users\...\anaconda3\envs\python39\lib\site-packages\whisper\transcribe.py", line 181, in transcribe
    ):
  File "C:\Users\...\anaconda3\envs\python39\lib\site-packages\whisper\transcribe.py", line 117, in decode_with_fallback
  File "C:\Users\...\anaconda3\envs\python39\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "C:\Users\...\anaconda3\envs\python39\lib\site-packages\whisper\decoding.py", line 705, in decode
    if completed or tokens.shape[-1] > self.n_ctx:
  File "C:\Users\...\anaconda3\envs\python39\lib\site-packages\whisper\decoding.py", line 468, in __init__
    if last_was_timestamp:
ValueError: tuple.index(x): x not in tuple

My code in this part of the application is this:

    actual_language=combo.get()
    
    archivo=filedialog.askopenfilename(initialdir = "./",
                 title = "Seleccione archivo",filetypes = (("all files","*.*"),("mp3 files","*.mp3"),
                 ("wav files","*.wav")))
    
    torch.cuda.is_available()
    DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
    
    model = whisper.load_model("medium")
   
    if archivo!="":
        try:
                    
            audio = whisper.load_audio(archivo)
            audio_trim = whisper.pad_or_trim(audio)
            
            mel = whisper.log_mel_spectrogram(audio_trim).to(model.device)
            
            result = model.transcribe(audio, language=f"{actual_language}", fp16=False, verbose=True)
            
            print(result["text"])

        except Exception as e:
            actual_status.set("¡Error!")
            logging.error('Error at %s', 'division', exc_info=e)

Before adding the language selection, I tried with automatic language recognition but the error was the same.

result = model.transcribe(audio)

or

audio = whisper.load_audio(file)
audio_trim = whisper.pad_or_trim(audio)

mel = whisper.log_mel_spectrogram(audio_trim).to(model.device)

_, probs = model.detect_language(mel)

options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)

With the selection, I tried using less options

result = model.transcribe(archivo,language=f"{actual_language}")

I'm using python 3.9 and I upgraded to last version wishper too.

1

There are 1 answers

0
Nacho Delgado On BEST ANSWER

Well... It was strange, I was writing the program with anaconda when I wrote this question, yesterday I tried to execute it with Visual Studio Code and it works. Today both programs coudn't use the pyaudio library so I had to reinstall it.

In this moment is working fine.