Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import base64
|
3 |
import io
|
@@ -15,8 +16,9 @@ def recognize_speech(audio_data, show_messages=True):
|
|
15 |
audio_recording = sr.Microphone(device_index=4, sample_rate=16000, chunk_size=1024)
|
16 |
|
17 |
with audio_recording as source:
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
try:
|
22 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|
@@ -37,10 +39,9 @@ def format_prompt(message, history):
|
|
37 |
prompt = "<s>"
|
38 |
|
39 |
for user_prompt, bot_response in history:
|
40 |
-
prompt += f"[
|
41 |
-
prompt += f" {bot_response}</s> "
|
42 |
|
43 |
-
prompt += f"[
|
44 |
return prompt
|
45 |
|
46 |
def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
@@ -83,6 +84,15 @@ def text_to_speech(text, speed=1.3):
|
|
83 |
modified_audio_fp.seek(0)
|
84 |
return modified_audio_fp
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
def main():
|
87 |
st.title("Chatbot de Voz a Voz")
|
88 |
audio_data = audiorecorder("Habla para grabar", "Deteniendo la grabaci贸n...")
|
|
|
1 |
+
import pyaudio
|
2 |
import streamlit as st
|
3 |
import base64
|
4 |
import io
|
|
|
16 |
audio_recording = sr.Microphone(device_index=4, sample_rate=16000, chunk_size=1024)
|
17 |
|
18 |
with audio_recording as source:
|
19 |
+
list_available_microphones()
|
20 |
+
recognizer.adjust_for_ambient_noise(source, gain=None)
|
21 |
+
audio = recognizer.listen(source, timeout=5, gain=None)
|
22 |
|
23 |
try:
|
24 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|
|
|
39 |
prompt = "<s>"
|
40 |
|
41 |
for user_prompt, bot_response in history:
|
42 |
+
prompt += f"[/s] {user_prompt} [/s] {bot_response}</s> "
|
|
|
43 |
|
44 |
+
prompt += f"[/s] {message} [/s]"
|
45 |
return prompt
|
46 |
|
47 |
def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
|
|
84 |
modified_audio_fp.seek(0)
|
85 |
return modified_audio_fp
|
86 |
|
87 |
+
def list_available_microphones():
|
88 |
+
p = pyaudio.PyAudio()
|
89 |
+
info = p.get_host_api_info_by_index(0)
|
90 |
+
numdevices = info.get('deviceCount')
|
91 |
+
for i in range(0, numdevices):
|
92 |
+
if (p.get_device_info_by_index(i).get('maxInputChannels')) > 0:
|
93 |
+
print("Input Device id {}: {}".format(i, p.get_device_info_by_index(i).get('name')))
|
94 |
+
p.terminate()
|
95 |
+
|
96 |
def main():
|
97 |
st.title("Chatbot de Voz a Voz")
|
98 |
audio_data = audiorecorder("Habla para grabar", "Deteniendo la grabaci贸n...")
|