User Tools

Site Tools


informatica:speech_to_text

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
informatica:speech_to_text [2023/03/20 01:07] joseinformatica: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 "$PWD":/audio local/speechtotext fichero.wav   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
 +<code>
 +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)
 +</code>
 +
 +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
 +
 +====== Servicio de Google ======
 +<code>
 +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('audio.wav') as source:
 +    # Leemos el audio del archivo
 +    audio = r.record(source)
 +
 +# Convertimos el audio a texto
 +text = r.recognize_google(audio, language='es-ES')
 +
 +# Generamos un nombre de archivo único para el texto
 +filename = 'texto_' + str(int(time.time())) + '.txt'
 +
 +# Guardamos el texto en un archivo de texto
 +with open(filename, 'w') as f:
 +    f.write(text)
 +</code>
 +
 +====== API TELEGRAM ======
 +/dades/web/htdocs/apitelegram.lobo99.info/speechtotext/bot.php
 +
 +Graba el archivo en el file system como AwAxxxxxxxx.ogg
 +
 +Lo pasa a http://vosk.lobo99.com/transcribir
 +
  
informatica/speech_to_text.1679274463.txt.gz · Last modified: 2023/03/20 01:07 by jose