Shweta7171 commited on
Commit
a75448e
·
verified ·
1 Parent(s): 12b52be

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +29 -0
  2. requirements.txt +1 -0
  3. utils.py +25 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils import *
3
+ import io
4
+
5
+
6
+
7
+ def main():
8
+ st.header('Welcome to the app')
9
+
10
+
11
+ mode = st.selectbox(label='select one', options=['Text-to-speech','Speech-to-text'])
12
+
13
+ if mode == 'Text-to-speech':
14
+ # st.write("calling text to speech function")
15
+ input_text = st.text_area("Enter the text here..")
16
+ if st.button("Generate Audio") and input_text:
17
+ response = text_to_speech(input_text)
18
+ if response:
19
+ st.audio(io.BytesIO(response.content))
20
+ elif mode == 'Speech-to-text':
21
+ # st.write('calling speech to text function')
22
+ audio_uploaded = st.file_uploader("Upload your file", type='.mp3')
23
+ if st.button("Generate transcript") and audio_uploaded:
24
+ text = audio_to_text(audio_uploaded)
25
+ st.write(text)
26
+
27
+
28
+ if __name__ == '__main__':
29
+ main()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ openai
utils.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from openai import OpenAI
3
+
4
+ def audio_to_text(audio_data):
5
+ client = OpenAI()
6
+
7
+ transcription = client.audio.transcriptions.create(
8
+ model="whisper-1",
9
+ file=audio_data,
10
+ response_format="text"
11
+ )
12
+ return transcription
13
+
14
+
15
+
16
+ def text_to_speech(text):
17
+ client = OpenAI()
18
+
19
+ response = client.audio.speech.create(
20
+ model="tts-1",
21
+ voice="shimmer",
22
+ input=text
23
+ )
24
+
25
+ return response