informatica:speech_to_text
This is an old revision of the document!
Línea de comandos con docker
Speech to text
https://github.com/alphacep/vosk-api
https://alphacephei.com/vosk/install
apt-get install python-is-python3 python-is-python3 python3-pip ffmpeg pip3 install vosk
vosk-transcriber -l es -i fichero.wav -o texto.txt
Dockerfile
FROM debian RUN apt-get update && apt-get install -y python-is-python3 python-is-python3 python3-pip ffmpeg RUN pip3 install vosk WORKDIR /audio ENTRYPOINT ["bash", "-c", "vosk-transcriber -l es -i $1 -o texto.txt >/dev/null 2>&1 && cat texto.txt", "--"]
docker run --rm -v "$PWD":/audio local/speechtotext fichero.wav
Como servicio web
Creamos el fichero vosk.py que levantará un servidor web que al hacer un post de un fichero de audio, devuelve el texto. Lo levantamos con el comando:
python3 vosk.py
from flask import Flask, request, jsonify import subprocess app = Flask(__name__) @app.route('/transcribir', methods=['POST']) def transcribir_audio(): archivo_audio = request.files['audio'] archivo_audio.save('audio.wav') subprocess.run(['vosk-transcriber', '-l', 'es', '-i', 'audio.wav', '-o', 'texto.txt']) with open('texto.txt', 'r') as f: texto = f.read() return jsonify({'texto': texto}) if __name__ == '__main__': app.run(debug=True,host='0.0.0.0',port=3000)
Se envía un audio con este comando y te devuelve el texto:
curl -X POST -F 'audio=@a.ogg' http://10.103.0.1:3000/transcribir
informatica/speech_to_text.1679409276.txt.gz · Last modified: 2023/03/21 14:34 by jose