informatica:speech_to_text
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
informatica:speech_to_text [2023/03/20 00:38] – created jose | informatica:speech_to_text [2023/04/14 08:31] (current) – jose | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Línea de comandos con docker ====== | ||
Speech to text | Speech to text | ||
Line 8: | Line 9: | ||
vosk-transcriber -l es -i fichero.wav -o texto.txt | 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 [" | ||
+ | |||
+ | </ | ||
+ | |||
+ | docker run --rm -v " | ||
+ | |||
+ | ====== 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('/ | ||
+ | def transcribir_audio(): | ||
+ | archivo_audio = request.files[' | ||
+ | archivo_audio.save(' | ||
+ | subprocess.run([' | ||
+ | with open(' | ||
+ | texto = f.read() | ||
+ | return jsonify({' | ||
+ | |||
+ | if __name__ == ' | ||
+ | app.run(debug=True, | ||
+ | </ | ||
+ | |||
+ | Se envía un audio con este comando y te devuelve el texto: | ||
+ | curl -X POST -F ' | ||
+ | |||
+ | ====== Servicio de Google ====== | ||
+ | < | ||
+ | import speech_recognition as sr | ||
+ | import time | ||
+ | |||
+ | # Creamos un objeto Recognizer | ||
+ | r = sr.Recognizer() | ||
+ | |||
+ | # Abrimos el archivo de audio y lo pasamos al objeto AudioFile | ||
+ | with sr.AudioFile(' | ||
+ | # Leemos el audio del archivo | ||
+ | audio = r.record(source) | ||
+ | |||
+ | # Convertimos el audio a texto | ||
+ | text = r.recognize_google(audio, | ||
+ | |||
+ | # Generamos un nombre de archivo único para el texto | ||
+ | filename = ' | ||
+ | |||
+ | # Guardamos el texto en un archivo de texto | ||
+ | with open(filename, | ||
+ | f.write(text) | ||
+ | </ | ||
+ | |||
+ | ====== API TELEGRAM ====== | ||
+ | / | ||
+ | |||
+ | Graba el archivo en el file system como AwAxxxxxxxx.ogg | ||
+ | |||
+ | Lo pasa a http:// | ||
+ | |||
informatica/speech_to_text.1679272738.txt.gz · Last modified: 2023/03/20 00:38 by jose