ThatOneCoder commited on
Commit
442be39
·
verified ·
1 Parent(s): 57a52f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -40
app.py CHANGED
@@ -1,41 +1,18 @@
1
  import streamlit as st
2
- import speech_recognition as sr
3
- from pydub import AudioSegment
4
-
5
- def convert_audio_to_wav(audio_file):
6
- audio = AudioSegment.from_file(audio_file)
7
- wav_file = audio_file.name.split(".")[0] + ".wav"
8
- audio.export(wav_file, format="wav")
9
- return wav_file
10
-
11
- def speech_to_text(audio_file):
12
- recognizer = sr.Recognizer()
13
- with sr.AudioFile(audio_file) as source:
14
- audio = recognizer.record(source)
15
- try:
16
- text = recognizer.recognize_google(audio)
17
- return text
18
- except sr.UnknownValueError:
19
- return "Could not understand audio"
20
- except sr.RequestError as e:
21
- return f"Error: {str(e)}"
22
-
23
- def main():
24
- st.title("Speech to Text Converter")
25
- st.write("Upload an audio file and convert it to text.")
26
-
27
- uploaded_file = st.file_uploader("Choose an audio file", type=["wav", "mp3"])
28
-
29
- if uploaded_file is not None:
30
- file_details = {"Filename": uploaded_file.name, "FileType": uploaded_file.type}
31
- st.write(file_details)
32
-
33
- if uploaded_file.type == "audio/mp3":
34
- uploaded_file = convert_audio_to_wav(uploaded_file)
35
-
36
- text = speech_to_text(uploaded_file)
37
- st.write("Converted Text:")
38
- st.write(text)
39
-
40
- if __name__ == "__main__":
41
- main()
 
1
  import streamlit as st
2
+ import streamlit.components.v1 as components
3
+
4
+ st.chat_input("biggie")
5
+ default_chat_input_value = "Default Value"
6
+ js = f"""
7
+ <script>
8
+ function insertText(dummy_var_to_force_repeat_execution) {{
9
+ var chatInput = parent.document.querySelector('textarea[data-testid="stChatInput"]');
10
+ var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
11
+ nativeInputValueSetter.call(chatInput, "{default_chat_input_value}");
12
+ var event = new Event('input', {{ bubbles: true}});
13
+ chatInput.dispatchEvent(event);
14
+ }}
15
+ insertText({len(st.session_state.messages)});
16
+ </script>
17
+ """
18
+ components(js)