You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import asyncio
import io
import os
import re
import tempfile
from pydub import AudioSegment
from pydub.playback import play
import edge_tts
import logging
logger = logging.getLogger(name)
async def async_get_speech(phrase,voice="zh-CN-XiaoxiaoNeural"):
try:
# 创建一个临时文件
with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
tmpfile_name = tmpfile.name
text=phrase
text = re.sub(r'*+', '', text) # 替换所有 * 字符
text = re.sub(r'#+', '', text)
phrase=text
# print(phrase)
# 生成语音并保存到临时文件
tts = edge_tts.Communicate(text=phrase,voice=voice)
await tts.save(tmpfile_name)
我有一个简单的实现,
AgentBase
def speak(
self,
content: Union[str, dict],
) -> None:
if self.is_tts:
logger.chat(content)
asyncio.run(async_get_speech(content.content))
else:
logger.chat(content)
采用edget_tts 库实现语音播放
import asyncio
import io
import os
import re
import tempfile
from pydub import AudioSegment
from pydub.playback import play
import edge_tts
import logging
logger = logging.getLogger(name)
async def async_get_speech(phrase,voice="zh-CN-XiaoxiaoNeural"):
try:
# 创建一个临时文件
with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
tmpfile_name = tmpfile.name
text=phrase
text = re.sub(r'*+', '', text) # 替换所有 * 字符
text = re.sub(r'#+', '', text)
phrase=text
# print(phrase)
# 生成语音并保存到临时文件
tts = edge_tts.Communicate(text=phrase,voice=voice)
await tts.save(tmpfile_name)
async def main():
phrase = "*Hello, #this is a test."
await async_get_speech(phrase)
if name == "main":
asyncio.run(main())
The text was updated successfully, but these errors were encountered: