-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.py
More file actions
44 lines (36 loc) · 1.15 KB
/
runner.py
File metadata and controls
44 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from retico_core.debug import DebugModule
from retico_core.audio import MicrophoneModule, SpeakerModule
from retico_googleasr import GoogleASRModule
from retico_huggingfacelm import HuggingfaceLM
from retico_speechbraintts import SpeechBrainTTSModule
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
device = "cuda" if torch.cuda.is_available() else "cpu"
checkpoint = "HuggingFaceTB/SmolLM2-135M-Instruct"
tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(checkpoint, trust_remote_code=True).to(device)
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
debug = DebugModule(print_payload_only=True)
mic = MicrophoneModule()
asr = GoogleASRModule(rate=16_000)
lm = HuggingfaceLM(device, tokenizer, model, streamer)
tts = SpeechBrainTTSModule("en")
speaker = SpeakerModule(rate=22050)
mic.subscribe(asr)
asr.subscribe(lm)
lm.subscribe(tts)
lm.subscribe(debug)
tts.subscribe(speaker)
mic.run()
asr.run()
lm.run()
tts.run()
speaker.run()
debug.run()
input()
mic.stop()
asr.stop()
lm.stop()
tts.stop()
speaker.stop()
debug.stop()