Spaces:
Sleeping
Sleeping
import gradio as gr | |
import openai | |
import time | |
import os | |
from pydub import AudioSegment | |
from pydub.silence import split_on_silence | |
openai_client = openai.OpenAI() | |
OPENAI_TRANSCRIPTION_MODEL = 'whisper-1' | |
whisper = openai_client.audio.transcriptions.create | |
WHISPER_TEMPERATURE = 0.0 | |
def transcribe_audio(audio_file): | |
audio = AudioSegment.from_file(audio_file) | |
chunks = split_on_silence(audio, min_silence_len=500, silence_thresh=-40) | |
transcription = "" | |
for i, chunk in enumerate(chunks): | |
chunk_file = f"CHUNKS/chunk_{i}.mp3" | |
chunk.export(chunk_file, format="mp3") | |
response = whisper(model = OPENAI_TRANSCRIPTION_MODEL, | |
file = open(chunk_file, 'rb'), | |
language = 'es', | |
temperature = WHISPER_TEMPERATURE) # to do, explore temperature | |
print(dir(response)) | |
transcription += response.text + " " | |
# os.remove(chunk_file) # concatenate at the end | |
yield transcription | |
iface = gr.Interface( | |
fn=transcribe_audio, | |
inputs = gr.Audio(sources=["microphone"], type="filepath"), | |
outputs="text", | |
live=True, # Enable live streaming | |
title="πππ Lucero-CETRAM-CORFO Transcripcion con Whisper πππ", | |
description="record using your microphone to get a transcription using OpenAI's Whisper API." | |
) | |
iface.launch() |