48 lines
1.0 KiB
Python
48 lines
1.0 KiB
Python
#encoding = utf8
|
|
|
|
import sys
|
|
import time
|
|
|
|
from asr import SherpaNcnnAsr
|
|
from nlp import PunctuationSplit
|
|
from nlp.nlp_doubao import DouBao
|
|
from tts import TTSEdge, TTSAudioSaveHandle
|
|
|
|
try:
|
|
import sounddevice as sd
|
|
except ImportError as e:
|
|
print("Please install sounddevice first. You can use")
|
|
print()
|
|
print(" pip install sounddevice")
|
|
print()
|
|
print("to install it")
|
|
sys.exit(-1)
|
|
|
|
|
|
def main():
|
|
print("Started! Please speak")
|
|
handle = TTSAudioSaveHandle(None, None)
|
|
tts = TTSEdge(handle)
|
|
split = PunctuationSplit()
|
|
nlp = DouBao(split, tts)
|
|
asr = SherpaNcnnAsr()
|
|
asr.attach(nlp)
|
|
time.sleep(60)
|
|
print("Stop! ")
|
|
asr.stop()
|
|
asr.detach(nlp)
|
|
nlp.stop()
|
|
tts.stop()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
devices = sd.query_devices()
|
|
print(devices)
|
|
default_input_device_idx = sd.default.device[0]
|
|
print(f'Use default device: {devices[default_input_device_idx]["name"]}')
|
|
|
|
try:
|
|
main()
|
|
except KeyboardInterrupt:
|
|
print("\nCaught Ctrl + C. Exiting")
|