[Python] Use Vosk speech recognition with Python

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to use Vosk speech recognition in a Python script, but the result is always :

    {
    "text" : ""
    }


    It's not a problem with my file because when I use in DOS "vosk-transcriber -l fr -i speech3.wav -o test6.txt" it works perfectly and I got a test6.txt with an accurate transcription.

    Here is my Python :

    import vosk

    # Load the Vosk model
    model = vosk.Model("voskSmallFr")

    # Initialize the recognizer with the model
    recognizer = vosk.KaldiRecognizer(model, 16000)

    # Sample audio file for recognition
    audio_file = "speech3.wav"

    # Open the audio file
    with open(audio_file, "rb") as audio:
    while True:
    # Read a chunk of the audio file
    data = audio.read(4000)
    if len(data) == 0:
    break
    # Recognize the speech in the chunk
    recognizer.AcceptWaveform(data)

    # Get the final recognized result
    result = recognizer.FinalResult()
    print(result)


    I downloaded and tried every models available in French (my wav file is in French) on the official Vosk website (4 in total), the scripts run well but give no results contrary to the Windows command...

    Any ideas? Thank you

    Continue reading...

Compartilhe esta Página