Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import pyaudio
|
2 |
import streamlit as st
|
3 |
import base64
|
4 |
import io
|
@@ -10,9 +9,6 @@ from pydub import AudioSegment
|
|
10 |
if "history" not in st.session_state:
|
11 |
st.session_state.history = []
|
12 |
|
13 |
-
for index, name in enumerate(sr.Microphone.list_microphone_names()):
|
14 |
-
print(f'{index}, {name}')
|
15 |
-
|
16 |
def recognize_speech(audio_data, show_messages=True):
|
17 |
recognizer = sr.Recognizer()
|
18 |
|
@@ -34,12 +30,6 @@ def recognize_speech(audio_data, show_messages=True):
|
|
34 |
|
35 |
return audio_text
|
36 |
|
37 |
-
def find_microphone():
|
38 |
-
microphones = sr.Microphone.list_microphone_names()
|
39 |
-
if not microphones:
|
40 |
-
st.error("No se encontraron dispositivos de micr贸fono. Aseg煤rate de tener un micr贸fono conectado.")
|
41 |
-
return microphones
|
42 |
-
|
43 |
def format_prompt(message, history):
|
44 |
prompt = "<s>"
|
45 |
|
@@ -91,39 +81,35 @@ def text_to_speech(text, speed=1.3):
|
|
91 |
return modified_audio_fp
|
92 |
|
93 |
def main():
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_file.read()).decode()}" type="audio/mp3" id="audio_player"></audio>
|
124 |
-
""",
|
125 |
-
unsafe_allow_html=True
|
126 |
-
)
|
127 |
|
128 |
if __name__ == "__main__":
|
129 |
main()
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import base64
|
3 |
import io
|
|
|
9 |
if "history" not in st.session_state:
|
10 |
st.session_state.history = []
|
11 |
|
|
|
|
|
|
|
12 |
def recognize_speech(audio_data, show_messages=True):
|
13 |
recognizer = sr.Recognizer()
|
14 |
|
|
|
30 |
|
31 |
return audio_text
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def format_prompt(message, history):
|
34 |
prompt = "<s>"
|
35 |
|
|
|
81 |
return modified_audio_fp
|
82 |
|
83 |
def main():
|
84 |
+
selected_microphone = "PulseAudio Default"
|
85 |
+
|
86 |
+
with sr.Microphone() as source:
|
87 |
+
st.write(f"Probando micr贸fono {selected_microphone}")
|
88 |
+
audio_data = recognize_speech(source)
|
89 |
+
|
90 |
+
if audio_data:
|
91 |
+
st.subheader(f"Audio Grabado con {selected_microphone}:")
|
92 |
+
st.audio(audio_data.get_wav_data(), format="audio/wav")
|
93 |
+
audio_text = recognize_speech(io.BytesIO(audio_data.get_wav_data()))
|
94 |
+
|
95 |
+
if not st.session_state.history:
|
96 |
+
pre_prompt = "Te Llamar谩s Chaman 4.0 y tus respuestas ser谩n sumamente breves."
|
97 |
+
output, _ = generate(pre_prompt, history=st.session_state.history)
|
98 |
+
st.session_state.history.append((pre_prompt, output))
|
99 |
+
|
100 |
+
if audio_text:
|
101 |
+
output, audio_file = generate(audio_text, history=st.session_state.history)
|
102 |
+
|
103 |
+
if audio_text:
|
104 |
+
st.session_state.history.append((audio_text, output))
|
105 |
+
|
106 |
+
if audio_file is not None:
|
107 |
+
st.markdown(
|
108 |
+
f"""
|
109 |
+
<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_file.read()).decode()}" type="audio/mp3" id="audio_player"></audio>
|
110 |
+
""",
|
111 |
+
unsafe_allow_html=True
|
112 |
+
)
|
|
|
|
|
|
|
|
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
main()
|