Ce sujet a été résolu
le code
```python
from vosk import Model, KaldiRecognizer
import json, wave
WAV_PATH = "audio.wav" # audio file
MODEL_PATH = "models/vosk-model-fr-0.22" # Model transcription. Model here:
https://alphacephei.com/vosk/models
OUTPUT_PATH = "transcript.txt" # Output file
wf = wave.open(WAV_PATH, "rb")
if wf.getsampwidth() != 2 or wf.getnchannels() != 1:
print("Warning: the file should preferably be a 16-bit PCM mono WAV. Convert it with ffmpeg if necessary (see readme).")
model = Model(MODEL_PATH)
rec = KaldiRecognizer(model, wf.getframerate())
with open(OUTPUT_PATH, "w", encoding="utf-8") as out:
while True:
data = wf.readframes(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
res = json.loads(rec.Result())
text = res.get("text", "").strip()
if text:
print(text)
out.write(text + "\n")
final = json.loads(rec.FinalResult())
final_text = final.get("text", "").strip()
if final_text:
print(final_text)
out.write(final_text + "\n")
wf.close()
print("Transcription enregistrée dans :", OUTPUT_PATH)
```
faut convertir en wav
```bash
ffmpeg -i "mon fichier audio ca mere " -ar 16000 -ac 1 -sample_fmt s16 "audio.wav"
```
ou je telecharge le model
https://alphacephei.com/vosk/models
démerder vous pour l'indentation

```python
from vosk import Model, KaldiRecognizer
import json, wave
WAV_PATH = "audio.wav" # audio file
MODEL_PATH = "models/vosk-model-fr-0.22" # Model transcription. Model here:
OUTPUT_PATH = "transcript.txt" # Output file
wf = wave.open(WAV_PATH, "rb")
if wf.getsampwidth() != 2 or wf.getnchannels() != 1:
print("Warning: the file should preferably be a 16-bit PCM mono WAV. Convert it with ffmpeg if necessary (see readme).")
model = Model(MODEL_PATH)
rec = KaldiRecognizer(model, wf.getframerate())
with open(OUTPUT_PATH, "w", encoding="utf-8") as out:
while True:
data = wf.readframes(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
res = json.loads(rec.Result())
text = res.get("text", "").strip()
if text:
print(text)
out.write(text + "\n")
final = json.loads(rec.FinalResult())
final_text = final.get("text", "").strip()
if final_text:
print(final_text)
out.write(final_text + "\n")
wf.close()
print("Transcription enregistrée dans :", OUTPUT_PATH)
```
faut convertir en wav

```bash
ffmpeg -i "mon fichier audio ca mere " -ar 16000 -ac 1 -sample_fmt s16 "audio.wav"
```
ou je telecharge le model

démerder vous pour l'indentation
il y a 4 mois
Wieirstrass
4 mois
le code
```python
from vosk import Model, KaldiRecognizer
import json, wave
WAV_PATH = "audio.wav" # audio file
MODEL_PATH = "models/vosk-model-fr-0.22" # Model transcription. Model here:
https://alphacephei.com/vosk/models
OUTPUT_PATH = "transcript.txt" # Output file
wf = wave.open(WAV_PATH, "rb")
if wf.getsampwidth() != 2 or wf.getnchannels() != 1:
print("Warning: the file should preferably be a 16-bit PCM mono WAV. Convert it with ffmpeg if necessary (see readme).")
model = Model(MODEL_PATH)
rec = KaldiRecognizer(model, wf.getframerate())
with open(OUTPUT_PATH, "w", encoding="utf-8") as out:
while True:
data = wf.readframes(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
res = json.loads(rec.Result())
text = res.get("text", "").strip()
if text:
print(text)
out.write(text + "\n")
final = json.loads(rec.FinalResult())
final_text = final.get("text", "").strip()
if final_text:
print(final_text)
out.write(final_text + "\n")
wf.close()
print("Transcription enregistrée dans :", OUTPUT_PATH)
```
faut convertir en wav
```bash
ffmpeg -i "mon fichier audio ca mere " -ar 16000 -ac 1 -sample_fmt s16 "audio.wav"
```
ou je telecharge le model
https://alphacephei.com/vosk/models
démerder vous pour l'indentation

```python
from vosk import Model, KaldiRecognizer
import json, wave
WAV_PATH = "audio.wav" # audio file
MODEL_PATH = "models/vosk-model-fr-0.22" # Model transcription. Model here:
OUTPUT_PATH = "transcript.txt" # Output file
wf = wave.open(WAV_PATH, "rb")
if wf.getsampwidth() != 2 or wf.getnchannels() != 1:
print("Warning: the file should preferably be a 16-bit PCM mono WAV. Convert it with ffmpeg if necessary (see readme).")
model = Model(MODEL_PATH)
rec = KaldiRecognizer(model, wf.getframerate())
with open(OUTPUT_PATH, "w", encoding="utf-8") as out:
while True:
data = wf.readframes(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
res = json.loads(rec.Result())
text = res.get("text", "").strip()
if text:
print(text)
out.write(text + "\n")
final = json.loads(rec.FinalResult())
final_text = final.get("text", "").strip()
if final_text:
print(final_text)
out.write(final_text + "\n")
wf.close()
print("Transcription enregistrée dans :", OUTPUT_PATH)
```
faut convertir en wav

```bash
ffmpeg -i "mon fichier audio ca mere " -ar 16000 -ac 1 -sample_fmt s16 "audio.wav"
```
ou je telecharge le model

démerder vous pour l'indentation
il y a 4 mois



