Spaces:
Running
Running
import io | |
import os | |
import gradio as gr | |
from google.cloud import speech | |
rutas = [os.getcwd(),"deploygpt-e9475e7c2c7c.json"] | |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = '/'.join(rutas) | |
def transcribe(file_name): | |
"""Transcribe audio bytes to text using Google Cloud Speech to Text.""" | |
if not file_name: | |
# Crea un cliente de Speech to Text | |
client = speech.SpeechClient() | |
# Configura la configuración de la solicitud | |
config = speech.RecognitionConfig( | |
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16, | |
enable_automatic_punctuation=True, | |
audio_channel_count=1, | |
language_code="es-AR", | |
) | |
# Crea una solicitud de reconocimiento de audio | |
with io.open(file_name, "rb") as audio_file: | |
content = audio_file.read() | |
audio = speech.RecognitionAudio(content=content) | |
# Realiza la transcripción | |
response = client.recognize(request={"config": config, "audio": audio}) | |
transcript = [] | |
# Reads the response | |
for result in response.results: | |
print("Transcript: {}".format(result.alternatives[0].transcript)) | |
transcript.append(result.alternatives[0].transcript) | |
return ' '.join(transcript) | |
return '' | |
demo = gr.Interface( | |
transcribe, | |
gr.Audio(sources=["microphone"], | |
type="filepath", # Crea un archivo temporal en formato wav | |
streaming=False), | |
"text" | |
) | |
demo.launch() | |