shukdevdatta123 commited on
Commit
0532e55
·
verified ·
1 Parent(s): e0db20e

Update helpers.py

Browse files
Files changed (1) hide show
  1. helpers.py +4 -8
helpers.py CHANGED
@@ -3,10 +3,10 @@ import streamlit as st
3
  import os
4
  import openai
5
  from dotenv import load_dotenv
 
6
 
7
  # Function to accept OpenAI API Key as input from the user
8
  def get_api_key():
9
- """Prompt the user for their OpenAI 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
@@ -18,13 +18,10 @@ 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", # Ensure the model is correct
22
  file=audio_file
23
  )
24
- return transcript["text"] # Extract the text from the response
25
-
26
-
27
- from gtts import gTTS
28
 
29
  def text_to_speech(input_text):
30
  """Generates a TTS audio file from the input text."""
@@ -33,7 +30,6 @@ def text_to_speech(input_text):
33
  tts.save(audio_file_path)
34
  return audio_file_path
35
 
36
-
37
  def autoplay_audio(file_path: str):
38
  with open(file_path, "rb") as f:
39
  data = f.read()
@@ -43,4 +39,4 @@ def autoplay_audio(file_path: str):
43
  <source src="data:audio/mp3;base64,{b64}" type="audio/mp3">
44
  </audio>
45
  """
46
- st.markdown(md, unsafe_allow_html=True)
 
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
 
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."""
 
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()
 
39
  <source src="data:audio/mp3;base64,{b64}" type="audio/mp3">
40
  </audio>
41
  """
42
+ st.markdown(md, unsafe_allow_html=True)