Zasha1 commited on
Commit
f72cf2b
·
verified ·
1 Parent(s): 8a86f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -10,6 +10,7 @@ import uuid
10
  import pandas as pd
11
  import plotly.express as px
12
  import streamlit as st
 
13
 
14
  # Initialize components
15
  objection_handler = ObjectionHandler('objections.csv')
@@ -17,30 +18,35 @@ product_recommender = ProductRecommender('recommendations.csv')
17
  model = SentenceTransformer('all-MiniLM-L6-v2')
18
 
19
  def list_audio_devices():
20
- """List available audio input devices."""
21
- recognizer = sr.Recognizer()
22
- mic_list = sr.Microphone.list_microphone_names()
23
- return mic_list
 
 
 
 
24
 
25
  def real_time_analysis():
26
  st.info("Listening... Say 'stop' to end the process.")
27
 
28
- recognizer = sr.Recognizer()
29
- sentiment_scores = []
30
- transcribed_chunks = []
31
- total_text = ""
32
-
33
  try:
34
  # List available audio devices
35
- mic_list = list_audio_devices()
36
- st.write(f"Available audio devices: {mic_list}")
 
 
37
 
38
- if not mic_list:
39
- st.error("No audio devices found. Please check the virtual microphone setup.")
40
  return
41
 
42
- # Use the virtual microphone (device index 0)
43
- mic = sr.Microphone(device_index=0) # Use the virtual microphone device index
 
 
 
 
44
 
45
  while True:
46
  with mic as source:
 
10
  import pandas as pd
11
  import plotly.express as px
12
  import streamlit as st
13
+ import pyaudio
14
 
15
  # Initialize components
16
  objection_handler = ObjectionHandler('objections.csv')
 
18
  model = SentenceTransformer('all-MiniLM-L6-v2')
19
 
20
  def list_audio_devices():
21
+ """List available audio input devices using pyaudio."""
22
+ p = pyaudio.PyAudio()
23
+ devices = []
24
+ for i in range(p.get_device_count()):
25
+ device_info = p.get_device_info_by_index(i)
26
+ if device_info["maxInputChannels"] > 0: # Check if it's an input device
27
+ devices.append(device_info)
28
+ return devices
29
 
30
  def real_time_analysis():
31
  st.info("Listening... Say 'stop' to end the process.")
32
 
 
 
 
 
 
33
  try:
34
  # List available audio devices
35
+ devices = list_audio_devices()
36
+ st.write("Available audio devices:")
37
+ for device in devices:
38
+ st.write(f"Device {device['index']}: {device['name']} (Input Channels: {device['maxInputChannels']})")
39
 
40
+ if not devices:
41
+ st.error("No audio input devices found. Please check the virtual microphone setup.")
42
  return
43
 
44
+ # Use the first available input device
45
+ device_index = devices[0]["index"]
46
+ st.write(f"Using device index {device_index}: {devices[0]['name']}")
47
+
48
+ recognizer = sr.Recognizer()
49
+ mic = sr.Microphone(device_index=device_index)
50
 
51
  while True:
52
  with mic as source: