configuration pour transcrire des fichiers audio wav avec Vosk
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
770 B

  1. #!/usr/bin/env python3
  2. from vosk import Model, KaldiRecognizer, SetLogLevel
  3. import sys
  4. import os
  5. import wave
  6. SetLogLevel(0)
  7. if not os.path.exists("model"):
  8. print ("Please download the model from https://alphacephei.com/vosk/models and unpack as 'model' in the current folder.")
  9. exit (1)
  10. wf = wave.open(sys.argv[1], "rb")
  11. if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
  12. print ("Audio file must be WAV format mono PCM.")
  13. exit (1)
  14. model = Model("model")
  15. rec = KaldiRecognizer(model, wf.getframerate())
  16. while True:
  17. data = wf.readframes(4000)
  18. if len(data) == 0:
  19. break
  20. if rec.AcceptWaveform(data):
  21. print(rec.Result())
  22. #else:
  23. # print(rec.PartialResult())
  24. print(rec.FinalResult())