Feat: Se mueven archivos a APP

This commit is contained in:
2024-11-01 17:57:44 -05:00
parent a5e9f2db81
commit 4be1115e3a
31 changed files with 1171 additions and 2 deletions

View File

45
app/api_openai/whisper.py Normal file
View File

@@ -0,0 +1,45 @@
from dotenv import load_dotenv
import os
from openai import OpenAI
def whisper_api(file_path: str) -> str:
# cargar la variable del entorno desde el archivo .env
load_dotenv()
# Usar la variable de entorno API_KEY
api_key: str = os.getenv("OPENAI_API_KEY")
# Cargar el modelo whisper
client = OpenAI(api_key=api_key)
audio_file = open(file_path, "rb")
transcription = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file,
response_format="text"
)
return transcription
def tts_api(text: str):
# cargar la variable del entorno desde el archivo .env
load_dotenv()
# Usar la variable de entorno API_KEY
api_key: str = os.getenv("OPENAI_API_KEY")
# Cargar el modelo whisper
client = OpenAI(api_key=api_key)
speech_file_path = os.path.join('audios', 'voice.ogg')
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input=text
)
response.stream_to_file(speech_file_path)
return speech_file_path