from src import ExecutePipeline from src import Plugins from src import EchoEngine from pathlib import Path def main(): from plugins.example import MyEngine plug_conf = Plugins(Path(__file__).resolve().parent) pipe = ExecutePipeline( plug_conf.load_engine("asr_engine"), MyEngine(), plug_conf.load_engine("chat_ai_engine"), EchoEngine(), plug_conf.load_engine("tts_engine"), ) res = pipe.execute_engines('./tests/offical/sounds/asr_example.wav') import wave import io import pyaudio # with open('output.wav', 'wb') as f: # f.write(res) wf = wave.open(io.BytesIO(res), 'rb') _audio = pyaudio.PyAudio() _stream = _audio.open(format=_audio.get_format_from_width(wf.getsampwidth()), channels=wf.getnchannels(), rate=wf.getframerate(), output=True) data = wf.readframes(1024) # 假定块大小为1024 while data: _stream.write(data) data = wf.readframes(1024) _stream.stop_stream() _stream.close() _audio.terminate() wf.close() if __name__ == '__main__': from dotenv import load_dotenv load_dotenv() # import importlib # from pathlib import Path # pug_path = Path(__file__).resolve().parent / "src/engine" # import sys # sys.path.append(str(pug_path)) # importlib.import_module("dashscope", # str(pug_path)) main()