Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import logging
3from askbob.action.responder import ResponseService
4from askbob.speech.transcriber import Transcriber
7def make_transcriber(config: dict, device: int, rate: int, filename: str, savepath: str) -> Transcriber:
8 """Makes a new transcriber instance from the parameters provided."""
10 if 'Listener' not in config:
11 raise RuntimeError(
12 "Missing Listener section in the runtime configuration file.")
14 if 'model' not in config['Listener']:
15 raise RuntimeError(
16 "Missing Listener.model in the runtime configuration file.")
18 model_path = config['Listener']['model']
19 scorer_path = config['Listener'].get('scorer', '')
21 if filename: 21 ↛ 26line 21 didn't jump to line 26, because the condition on line 21 was never false
22 from askbob.speech.listener.file import FileUtteranceService
23 us = FileUtteranceService(filename=filename, aggressiveness=config['Listener'].getint(
24 'aggressiveness', fallback=1))
25 else:
26 from askbob.speech.listener.mic import MicUtteranceService
27 us = MicUtteranceService(aggressiveness=config['Listener'].getint('aggressiveness', fallback=1),
28 device_index=device,
29 input_rate=rate)
31 return Transcriber(model=model_path, scorer=scorer_path, us=us, save_path=savepath)
34async def interactive_loop(args, config, responder: ResponseService):
35 """The main interactive loop for Ask Bob.
37 Args:
38 args: CLI-provided arguments
39 config: config.ini runtime configuration provided parameters
40 responder (ResponseService): The response service handling queries
41 """
43 if 'TTS' not in config or 'voice_id' not in config['TTS']:
44 logging.error(
45 "Missing voice_id in the runtime configuration ini file.")
46 return
48 from askbob.speech.synthesiser import TextToSpeechService
49 from askbob.speech.transcriber import TranscriptionEvent
50 import halo
52 try:
53 transcriber = make_transcriber(
54 config, args.device, args.rate, args.file, args.savepath)
55 except Exception as e:
56 logging.error(f"Unable to make the transcriber: {str(e)}")
57 return
59 speaker = TextToSpeechService(config['TTS']['voice_id'])
60 spinner = halo.Halo(spinner='line')
62 print("Listening (press Ctrl-C to exit).")
63 for state, text in transcriber.transcribe(): 63 ↛ exitline 63 didn't return from function 'interactive_loop', because the loop on line 63 didn't complete
64 if state == TranscriptionEvent.START_UTTERANCE:
65 spinner.start()
66 elif state == TranscriptionEvent.END_UTTERANCE: 66 ↛ 63line 66 didn't jump to line 63, because the condition on line 66 was never false
67 spinner.stop()
69 if text: 69 ↛ 86line 69 didn't jump to line 86, because the condition on line 69 was never false
70 print("==", text)
71 async for response in responder.handle(text):
72 if "text" in response:
73 print("=>", response["text"])
74 speaker.say(response["text"])
76 # Concierge integration
77 elif "custom" in response and "Response" in response["custom"]: 77 ↛ 71line 77 didn't jump to line 71, because the condition on line 77 was never false
78 print("=>", response["custom"]["Response"])
79 speaker.say(response["custom"]["Response"])
81 if "Steps" in response["custom"]: 81 ↛ 71line 81 didn't jump to line 71, because the condition on line 81 was never false
82 for step in response["custom"]["Steps"]:
83 print("===>", step)
84 speaker.say(step)
86 if args.file: 86 ↛ 63line 86 didn't jump to line 63, because the condition on line 86 was never false
87 return