informatica:speech_to_text
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatica:speech_to_text [2023/03/20 01:07] – 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 24: | Line 25: | ||
| docker run --rm -v " | 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.1679274463.txt.gz · Last modified: by jose
