ThatOneCoder commited on
Commit
ac0462b
·
verified ·
1 Parent(s): 8d67459

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -32
app.py CHANGED
@@ -1,37 +1,25 @@
1
  import streamlit as st
2
- from bokeh.models.widgets import Button
3
- from bokeh.models import CustomJS
4
- from streamlit_bokeh_events import streamlit_bokeh_events
5
 
6
- stt_button = Button(label="Speak", width=100)
7
 
8
- stt_button.js_on_event("button_click", CustomJS(code="""
9
- var recognition = new webkitSpeechRecognition();
10
- recognition.continuous = true;
11
- recognition.interimResults = true;
12
-
13
- recognition.onresult = function (e) {
14
- var value = "";
15
- for (var i = e.resultIndex; i < e.results.length; ++i) {
16
- if (e.results[i].isFinal) {
17
- value += e.results[i][0].transcript;
18
- }
19
- }
20
- if ( value != "") {
21
- document.dispatchEvent(new CustomEvent("GET_TEXT", {detail: value}));
22
- }
23
- }
24
- recognition.start();
25
- """))
26
 
27
- result = streamlit_bokeh_events(
28
- stt_button,
29
- events="GET_TEXT",
30
- key="listen",
31
- refresh_on_update=False,
32
- override_height=75,
33
- debounce_time=0)
34
 
35
- if result:
36
- if "GET_TEXT" in result:
37
- st.write(result.get("GET_TEXT"))
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from streamlit_mic_recorder import mic_recorder,speech_to_text
 
 
3
 
4
+ state=st.session_state
5
 
6
+ if 'text_received' not in state:
7
+ state.text_received=[]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ c1,c2=st.columns(2)
10
+ with c1:
11
+ st.write("Convert speech to text:")
12
+ with c2:
13
+ text=speech_to_text(language='en',use_container_width=True,just_once=True,key='STT')
 
 
14
 
15
+ if text:
16
+ state.text_received.append(text)
17
+
18
+ for text in state.text_received:
19
+ st.text(text)
20
+
21
+ st.write("Record your voice, and play the recorded audio:")
22
+ audio=mic_recorder(start_prompt="⏺️",stop_prompt="⏹️",key='recorder')
23
+
24
+ if audio:
25
+ st.audio(audio['bytes'])