Zasha1 commited on
Commit
e34fac6
·
verified ·
1 Parent(s): 1ed4f7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -8
app.py CHANGED
@@ -37,16 +37,43 @@ def numpy_to_audio_data(audio_data):
37
  return audio_data
38
 
39
  def real_time_analysis():
40
- recognizer = sr.Recognizer()
41
- mic = sr.Microphone()
42
-
43
- st.info("Say 'stop' to end the process.")
44
 
45
- sentiment_scores = []
46
- transcribed_chunks = []
47
- total_text = ""
 
 
 
48
 
49
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  while True:
51
  with mic as source:
52
  st.write("Listening...")
@@ -62,6 +89,7 @@ def real_time_analysis():
62
  st.write("Stopping real-time analysis...")
63
  break
64
 
 
65
  # Append to the total conversation
66
  total_text += text + " "
67
  sentiment, score = analyze_sentiment(text)
@@ -116,7 +144,7 @@ def real_time_analysis():
116
 
117
  except Exception as e:
118
  st.error(f"Error in real-time analysis: {e}")
119
-
120
 
121
  def generate_comprehensive_summary(chunks):
122
  """
 
37
  return audio_data
38
 
39
  def real_time_analysis():
40
+ st.info("Note: If microphone access fails, please use text input.")
 
 
 
41
 
42
+ try:
43
+ # Try to list available microphones
44
+ available_mics = sr.Microphone.list_microphone_names()
45
+ st.write(f"Available microphones: {available_mics}")
46
+ except Exception as e:
47
+ st.warning(f"Could not detect microphones: {e}")
48
 
49
  try:
50
+ # Try multiple device indices
51
+ mic = None
52
+ for device_index in range(10): # Try first 10 device indices
53
+ try:
54
+ mic = sr.Microphone(device_index=device_index)
55
+ st.write(f"Using microphone at device index {device_index}")
56
+ break
57
+ except Exception:
58
+ continue
59
+
60
+ if mic is None:
61
+ # Fallback to text input if no microphone works
62
+ st.warning("No microphone available. Switching to text input.")
63
+ text_input = st.text_input("Enter conversation text:")
64
+ if text_input:
65
+ sentiment, score = analyze_sentiment(text_input)
66
+ st.write(f"*Recognized Text:* {text_input}")
67
+ st.write(f"*Sentiment:* {sentiment} (Score: {score})")
68
+ return
69
+
70
+ recognizer = sr.Recognizer()
71
+ sentiment_scores = []
72
+ transcribed_chunks = []
73
+ total_text = ""
74
+
75
+ st.info("Say 'stop' to end the process.")
76
+
77
  while True:
78
  with mic as source:
79
  st.write("Listening...")
 
89
  st.write("Stopping real-time analysis...")
90
  break
91
 
92
+
93
  # Append to the total conversation
94
  total_text += text + " "
95
  sentiment, score = analyze_sentiment(text)
 
144
 
145
  except Exception as e:
146
  st.error(f"Error in real-time analysis: {e}")
147
+ st.warning("Unable to access microphone. Please use text input.")
148
 
149
  def generate_comprehensive_summary(chunks):
150
  """