🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fixbug: remove aiofile
莘权 马a5ab5948c9f9
diff --git a/metagpt/tools/azure_tts.py b/metagpt/tools/azure_tts.pyindex 0dc16d516..6864faf10 100644--- a/metagpt/tools/azure_tts.py+++ b/metagpt/tools/azure_tts.py@@ -7,18 +7,15 @@@Desc : azure TTS OAS3 api, which provides text-to-speech functionality"""import asyncio+import base64from pathlib import Pathfrom uuid import uuid4-import base64-import sys+import aiofiles+from azure.cognitiveservices.speech import AudioConfig, SpeechConfig, SpeechSynthesizerfrom metagpt.config import CONFIG, Config--sys.path.append(str(Path(__file__).resolve().parent.parent.parent)) # fix-bug: No module named 'metagpt'from metagpt.logs import logger-from aiofile import async_open-from azure.cognitiveservices.speech import AudioConfig, SpeechConfig, SpeechSynthesizerclass AzureTTS:@@ -34,18 +31,17 @@ class AzureTTS:# 参数参考:https://learn.microsoft.com/zh-cn/azure/cognitive-services/speech-service/language-support?tabs=tts#voice-styles-and-rolesasync def synthesize_speech(self, lang, voice, text, output_file):- speech_config = SpeechConfig(- subscription=self.subscription_key, region=self.region)+ speech_config = SpeechConfig(subscription=self.subscription_key, region=self.region)speech_config.speech_synthesis_voice_name = voiceaudio_config = AudioConfig(filename=output_file)- synthesizer = SpeechSynthesizer(- speech_config=speech_config,- audio_config=audio_config)+ synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)# More detail: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/speech-synthesis-markup-voice- ssml_string = "<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' " \- f"xml:lang='{lang}' xmlns:mstts='http://www.w3.org/2001/mstts'>" \- f"<voice name='{voice}'>{text}</voice></speak>"+ ssml_string = (+ "<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' "+ f"xml:lang='{lang}' xmlns:mstts='http://www.w3.org/2001/mstts'>"+ f"<voice name='{voice}'>{text}</voice></speak>"+ )return synthesizer.speak_ssml_async(ssml_string).get()@@ -100,7 +96,7 @@ async def oas3_azsure_tts(text, lang="", voice="", style="", role="", subscriptiawait tts.synthesize_speech(lang=lang, voice=voice, text=xml_value, output_file=str(filename))async with aiofiles.open(filename, mode="rb") as reader:data = await reader.read()- base64_string = base64.b64encode(data).decode('utf-8')+ base64_string = base64.b64encode(data).decode("utf-8")filename.unlink()except Exception as e:logger.error(f"text:{text}, error:{e}")