Spaces:
Sleeping
Sleeping
File size: 1,375 Bytes
d1f611f e6bde5b d1f611f e6bde5b d1f611f 23f8016 d1f611f 23f8016 d1f611f 34819e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# from whisper_jax import FlaxWhisperPipline
# import jax.numpy as jnp
# import whisper
# print(whisper.__file__)
from openai import OpenAI
from decouple import config
import os
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
client = OpenAI()
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
# def whisper_pipeline_tpu(audio):
# pipeline = FlaxWhisperPipline("openai/whisper-large-v3", dtype=jnp.bfloat16, batch_size=16)
# text = pipeline(audio)
# return text
# def whisper_pipeline(audio_path):
# model = whisper.load_model("medium")
# # load audio and pad/trim it to fit 30 seconds
# audio = whisper.load_audio(audio_path)
# audio = whisper.pad_or_trim(audio)
# # make log-Mel spectrogram and move to the same device as the model
# mel = whisper.log_mel_spectrogram(audio).to(model.device)
# # detect the spoken language
# _, probs = model.detect_language(mel)
# print(f"Detected language: {max(probs, key=probs.get)}")
# # decode the audio
# options = whisper.DecodingOptions()
# result = whisper.decode(model, mel, options)
# # print the recognized text
# print(result.text)
# return result.text
def whisper_openai(audio_path):
audio_file= open(audio_path, "rb")
transcript = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
return transcript |