human/test/asr_nlp_tts.py

48 lines
1.0 KiB
Python
Raw Permalink Normal View History

2024-10-10 11:01:13 +00:00
#encoding = utf8
import sys
import time
from asr import SherpaNcnnAsr
from nlp import PunctuationSplit
from nlp.nlp_doubao import DouBao
2024-10-11 12:09:54 +00:00
from tts import TTSEdge, TTSAudioSaveHandle
2024-10-10 11:01:13 +00:00
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")
2024-10-19 19:28:49 +00:00
handle = TTSAudioSaveHandle(None, None)
2024-10-11 12:09:54 +00:00
tts = TTSEdge(handle)
2024-10-10 11:01:13 +00:00
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")