Delete helpers.py
Browse files- helpers.py +0 -42
helpers.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
import base64
|
2 |
-
import streamlit as st
|
3 |
-
import os
|
4 |
-
import openai
|
5 |
-
from dotenv import load_dotenv
|
6 |
-
from gtts import gTTS
|
7 |
-
|
8 |
-
# Function to accept OpenAI API Key as input from the user
|
9 |
-
def get_api_key():
|
10 |
-
api_key = st.text_input("Enter your OpenAI API Key", type="password")
|
11 |
-
if api_key:
|
12 |
-
openai.api_key = api_key
|
13 |
-
return api_key
|
14 |
-
else:
|
15 |
-
return None
|
16 |
-
|
17 |
-
def speech_to_text(audio_data):
|
18 |
-
"""Transcribes audio data to text using OpenAI's API."""
|
19 |
-
with open(audio_data, "rb") as audio_file:
|
20 |
-
transcript = openai.Audio.transcribe(
|
21 |
-
model="whisper-1",
|
22 |
-
file=audio_file
|
23 |
-
)
|
24 |
-
return transcript["text"]
|
25 |
-
|
26 |
-
def text_to_speech(input_text):
|
27 |
-
"""Generates a TTS audio file from the input text."""
|
28 |
-
tts = gTTS(text=input_text, lang="en")
|
29 |
-
audio_file_path = "temp_audio_play.mp3"
|
30 |
-
tts.save(audio_file_path)
|
31 |
-
return audio_file_path
|
32 |
-
|
33 |
-
def autoplay_audio(file_path: str):
|
34 |
-
with open(file_path, "rb") as f:
|
35 |
-
data = f.read()
|
36 |
-
b64 = base64.b64encode(data).decode("utf-8")
|
37 |
-
md = f"""
|
38 |
-
<audio autoplay>
|
39 |
-
<source src="data:audio/mp3;base64,{b64}" type="audio/mp3">
|
40 |
-
</audio>
|
41 |
-
"""
|
42 |
-
st.markdown(md, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|