Spaces:
Build error
Build error
AdrianLambdaVerde
commited on
Commit
·
ace928d
1
Parent(s):
fdeb937
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,46 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
import
|
4 |
|
|
|
|
|
5 |
|
6 |
st.markdown("<h1 style='text-align: center;'>Tell us how you feel</h1>", unsafe_allow_html=True)
|
7 |
|
8 |
st.write("<h3 style='text-align: center; color: lightSeaGreen;'>we'll generate the insights</h3>", unsafe_allow_html=True)
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
# When the user clicks the button, start recording the user's speech.
|
17 |
-
if button.clicked:
|
18 |
-
speech_recorder.start()
|
19 |
|
20 |
-
# When the user stops recording, return a transcript of the user's speech.
|
21 |
-
if speech_recorder.is_finished:
|
22 |
-
transcript = speech_recorder.get_transcript()
|
23 |
-
st.write(transcript)
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
import streamlit as st
|
4 |
+
from audiorecorder import audiorecorder
|
5 |
+
import requests
|
6 |
|
7 |
+
STT_API_KEY = "gV6KiOm_eDrOisgI9B9hBbcTeNEwYQT4XNLJNLaI6DMk" #see discord
|
8 |
+
STT_URL = "https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/de074216-e340-4d56-b391-406532c98440/v1/recognize" #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.flac", format="flac")
|
23 |
+
|
24 |
+
# Convert audio to text
|
25 |
+
|
26 |
+
headers = {
|
27 |
+
"Content-Type": "audio/flac"
|
28 |
+
}
|
29 |
+
|
30 |
+
with open("audio.flac", "rb") as f:
|
31 |
+
response = requests.post(STT_URL, auth=("apikey", STT_API_KEY), headers=headers, files={'audio.flac': f})
|
32 |
+
|
33 |
+
response_json = response.json()
|
34 |
+
print(response_json)
|
35 |
+
if response_json["results"]:
|
36 |
+
response_text = response_json["results"][0]["alternatives"][0]["transcript"]
|
37 |
+
else:
|
38 |
+
response_text = "No audio detected"
|
39 |
+
print(response_text)
|
40 |
|
41 |
+
# To get audio properties, use pydub AudioSegment properties:
|
42 |
+
st.text_area(label="Output",
|
43 |
+
value=response_text,
|
44 |
+
height=300)
|
45 |
|
|
|
|
|
|
|
46 |
|
|
|
|
|
|
|
|