Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,14 @@
|
|
1 |
import io
|
2 |
import base64
|
3 |
-
import pyaudio
|
4 |
-
import webrtcvad
|
5 |
import threading
|
6 |
import numpy as np
|
7 |
from gtts import gTTS
|
8 |
import streamlit as st
|
9 |
-
import sounddevice as sd
|
10 |
import speech_recognition as sr
|
11 |
from huggingface_hub import InferenceClient
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
info = p.get_host_api_info_by_index(0)
|
16 |
-
num_devices = info.get('deviceCount')
|
17 |
-
devices = []
|
18 |
-
|
19 |
-
for i in range(num_devices):
|
20 |
-
device_info = p.get_device_info_by_host_api_device_index(0, i)
|
21 |
-
devices.append(device_info['name'])
|
22 |
-
|
23 |
-
p.terminate()
|
24 |
-
return devices
|
25 |
-
|
26 |
-
devices = sd.query_devices()
|
27 |
-
print(devices)
|
28 |
|
29 |
if "history" not in st.session_state:
|
30 |
st.session_state.history = []
|
@@ -141,16 +125,24 @@ class Threader(threading.Thread):
|
|
141 |
print("Started mythread")
|
142 |
start_stream()
|
143 |
|
144 |
-
available_audio_devices = list_audio_devices()
|
145 |
-
print("Dispositivos de audio disponibles:")
|
146 |
-
print(available_audio_devices)
|
147 |
-
selected_device = st.selectbox("Selecciona el micr贸fono:", available_audio_devices, index=0)
|
148 |
-
channels = [1]
|
149 |
-
mapping = [c - 1 for c in channels]
|
150 |
-
device_info = sd.query_devices(selected_device, 'input')
|
151 |
-
sample_rate = int(device_info['default_samplerate'])
|
152 |
-
|
153 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
vad = webrtcvad.Vad(1)
|
156 |
|
@@ -163,4 +155,4 @@ if __name__ == "__main__":
|
|
163 |
block_size = int(sample_rate * interval_size / 1000)
|
164 |
|
165 |
Threader(name='mythread')
|
166 |
-
st.button("Detener Stream")
|
|
|
1 |
import io
|
2 |
import base64
|
|
|
|
|
3 |
import threading
|
4 |
import numpy as np
|
5 |
from gtts import gTTS
|
6 |
import streamlit as st
|
|
|
7 |
import speech_recognition as sr
|
8 |
from huggingface_hub import InferenceClient
|
9 |
+
from streamlit_mic_recorder import mic_recorder
|
10 |
+
import wave
|
11 |
+
import webrtcvad
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
if "history" not in st.session_state:
|
14 |
st.session_state.history = []
|
|
|
125 |
print("Started mythread")
|
126 |
start_stream()
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
if __name__ == "__main__":
|
129 |
+
# Cambios para usar streamlit_mic_recorder
|
130 |
+
st.write("Record your voice, and play the recorded audio:")
|
131 |
+
audio = mic_recorder(start_prompt="鈻讹笍", stop_prompt="馃洃", key='recorder')
|
132 |
+
|
133 |
+
if audio:
|
134 |
+
st.audio(audio['bytes'])
|
135 |
+
|
136 |
+
audio_bytes = audio["bytes"]
|
137 |
+
sample_width = audio["sample_width"]
|
138 |
+
sample_rate = audio["sample_rate"]
|
139 |
+
num_channels = 1
|
140 |
+
|
141 |
+
with wave.open(temp_audio_file_path, 'w') as wave_file:
|
142 |
+
wave_file.setnchannels(num_channels)
|
143 |
+
wave_file.setsampwidth(sample_width)
|
144 |
+
wave_file.setframerate(sample_rate)
|
145 |
+
wave_file.writeframes(audio_bytes)
|
146 |
|
147 |
vad = webrtcvad.Vad(1)
|
148 |
|
|
|
155 |
block_size = int(sample_rate * interval_size / 1000)
|
156 |
|
157 |
Threader(name='mythread')
|
158 |
+
st.button("Detener Stream")
|