Sarthak-Dayal commited on
Commit
dd6635f
·
1 Parent(s): e674e7e

initial frontend

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ import streamlit as st
4
+ from audiorecorder import audiorecorder
5
+ import requests
6
+
7
+ STT_API_KEY = 0 #see discord
8
+ STT_URL = 0 #see discord
9
+
10
+ st.markdown("<h1 style='text-align: center;'>Tell us how you feel</h1>", unsafe_allow_html=True)
11
+
12
+ st.write("<h3 style='text-align: center; color: lightSeaGreen;'>we'll generate the insights</h3>", unsafe_allow_html=True)
13
+
14
+ audio = audiorecorder("Click to record", "Click to stop recording")
15
+
16
+
17
+ if not audio.empty():
18
+ # To play audio in frontend:
19
+ st.audio(audio.export().read())
20
+
21
+ # To save audio to a file, use pydub export method:
22
+ audio.export("audio.wav", format="wav")
23
+
24
+ # Convert audio to text
25
+
26
+ headers = {
27
+ "Content-Type": "audio/wav"
28
+ }
29
+
30
+ with open("audio.wav", "rb") as f:
31
+ response = requests.post(STT_URL, auth=("apikey", STT_API_KEY), headers=headers, files={'audio.wav': f})
32
+
33
+ response_json = response.json()
34
+ response_text = json.dumps(response_json)
35
+
36
+ # To get audio properties, use pydub AudioSegment properties:
37
+ st.text_area(label="Output",
38
+ value=f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds, JSON: {response_text}",
39
+ height=300)