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

Update sentiment_analysis.py

Browse files
Files changed (1) hide show
  1. sentiment_analysis.py +25 -7
sentiment_analysis.py CHANGED
@@ -60,12 +60,29 @@ def analyze_sentiment(text):
60
  return "NEUTRAL", 0.5
61
 
62
  def transcribe_with_chunks(objections_dict):
63
- """Perform real-time transcription with sentiment analysis."""
64
- print("Say 'start listening' to begin transcription. Say 'stop listening' to stop.")
65
- is_listening = False
66
- chunks = []
67
- current_chunk = []
68
- chunk_start_time = time.time()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  # Initialize handlers with semantic search capabilities
71
  objection_handler = ObjectionHandler(r"C:\Users\shaik\Downloads\Sales Calls Transcriptions - Sheet3.csv")
@@ -75,7 +92,7 @@ def transcribe_with_chunks(objections_dict):
75
  model = SentenceTransformer('all-MiniLM-L6-v2')
76
 
77
  try:
78
- with Microphone() as source:
79
  recognizer.adjust_for_ambient_noise(source)
80
  print("Microphone calibrated. Please speak.")
81
 
@@ -85,6 +102,7 @@ def transcribe_with_chunks(objections_dict):
85
  audio_data = recognizer.listen(source, timeout=5)
86
  text = recognizer.recognize_google(audio_data)
87
 
 
88
  if "start listening" in text.lower():
89
  is_listening = True
90
  print("Listening started. Speak into the microphone.")
 
60
  return "NEUTRAL", 0.5
61
 
62
  def transcribe_with_chunks(objections_dict):
63
+ print("Note: If microphone access fails, please use alternative input.")
64
+
65
+ try:
66
+ # Try to list available microphones
67
+ available_mics = Microphone.list_microphone_names()
68
+ print(f"Available microphones: {available_mics}")
69
+ except Exception as e:
70
+ print(f"Could not detect microphones: {e}")
71
+
72
+ try:
73
+ # Try multiple device indices
74
+ mic = None
75
+ for device_index in range(10): # Try first 10 device indices
76
+ try:
77
+ mic = Microphone(device_index=device_index)
78
+ print(f"Using microphone at device index {device_index}")
79
+ break
80
+ except Exception:
81
+ continue
82
+
83
+ if mic is None:
84
+ print("No microphone available. Please provide text input.")
85
+ return []
86
 
87
  # Initialize handlers with semantic search capabilities
88
  objection_handler = ObjectionHandler(r"C:\Users\shaik\Downloads\Sales Calls Transcriptions - Sheet3.csv")
 
92
  model = SentenceTransformer('all-MiniLM-L6-v2')
93
 
94
  try:
95
+ with mic as source:
96
  recognizer.adjust_for_ambient_noise(source)
97
  print("Microphone calibrated. Please speak.")
98
 
 
102
  audio_data = recognizer.listen(source, timeout=5)
103
  text = recognizer.recognize_google(audio_data)
104
 
105
+
106
  if "start listening" in text.lower():
107
  is_listening = True
108
  print("Listening started. Speak into the microphone.")