MCPcopy
hub / github.com/geekcomputers/Python / recognize_audio

Function recognize_audio

JARVIS/speech.py:106–122  ·  view source on GitHub ↗
(audio, recognizer)

Source from the content-addressed store, hash-verified

104
105
106def recognize_audio(audio, recognizer):
107 candidates = []
108 for language in SPEECH_LANGUAGES:
109 try:
110 result = recognizer.recognize_google(audio, language=language, show_all=True)
111 except Exception:
112 continue
113 alternatives = result.get("alternative", []) if isinstance(result, dict) else []
114 candidates.extend(item.get("transcript", "") for item in alternatives if item.get("transcript"))
115 unique_candidates = []
116 seen = set()
117 for candidate in candidates:
118 key = normalize_text(candidate)
119 if key and key not in seen:
120 seen.add(key)
121 unique_candidates.append(candidate)
122 return unique_candidates
123
124
125def listen_once(recognizer, source, choose_best_candidate):

Callers 1

listen_onceFunction · 0.85

Calls 5

normalize_textFunction · 0.85
extendMethod · 0.80
getMethod · 0.45
addMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected