2024-10-14 10:20:55 +00:00
|
|
|
#encoding = utf8
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from asr import SherpaNcnnAsr
|
|
|
|
from nlp import PunctuationSplit
|
|
|
|
from nlp.nlp_doubao import DouBao
|
2024-10-19 10:47:34 +00:00
|
|
|
from tts import TTSEdge, TTSAudioSaveHandle, TTSEdgeHttp
|
2024-10-14 10:20:55 +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 10:47:34 +00:00
|
|
|
handle = TTSAudioSaveHandle(None, None)
|
|
|
|
# tts = TTSEdge(handle)
|
|
|
|
tts = TTSEdgeHttp(handle)
|
2024-10-14 10:20:55 +00:00
|
|
|
split = PunctuationSplit()
|
|
|
|
nlp = DouBao(split, tts)
|
|
|
|
nlp.ask('你好,你是谁?')
|
|
|
|
nlp.ask('可以帮我做什么?')
|
2024-10-19 10:47:34 +00:00
|
|
|
nlp.ask('背诵出师表')
|
2024-10-14 10:20:55 +00:00
|
|
|
nlp.stop()
|
|
|
|
tts.stop()
|
|
|
|
print("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")
|