From da33ef41ee88c794c25fe472c72b389162019d62 Mon Sep 17 00:00:00 2001 From: FHY Date: Sat, 15 Feb 2025 03:40:28 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E7=A1=85=E5=9F=BA?= =?UTF-8?q?=E6=B5=81=E5=8A=A8tts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 7 ++++++ core/providers/tts/siliconflow.py | 41 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 core/providers/tts/siliconflow.py diff --git a/config.yaml b/config.yaml index 644592a7..b1fc7555 100644 --- a/config.yaml +++ b/config.yaml @@ -114,3 +114,10 @@ TTS: appid: 你的火山引擎语音合成服务appid access_token: 你的火山引擎语音合成服务access_token cluster: volcano_tts +CosyVoiceSiliconflow: + type: siliconflow + model: FunAudioLLM/CosyVoice2-0.5B + voice: FunAudioLLM/CosyVoice2-0.5B:alex + output_file: tmp/ + access_token: 你的硅基流动API密钥 + response_format: wav diff --git a/core/providers/tts/siliconflow.py b/core/providers/tts/siliconflow.py new file mode 100644 index 00000000..faca4405 --- /dev/null +++ b/core/providers/tts/siliconflow.py @@ -0,0 +1,41 @@ +import os +import uuid +import json +import base64 +import requests +from datetime import datetime +from core.providers.tts.base import TTSProviderBase + + +class TTSProvider(TTSProviderBase): + def __init__(self, config, delete_audio_file): + super().__init__(config, delete_audio_file) + self.model = config.get("model") + self.access_token = config.get("access_token") + self.voice = config.get("voice") + self.response_format = config.get("response_format") + self.sample_rate = config.get("sample_rate") + self.speed = config.get("speed") + self.gain = config.get("gain") + + self.host = "api.siliconflow.cn" + self.api_url = f"https://{self.host}/v1/audio/speech" + + def generate_filename(self, extension=".wav"): + return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}") + + async def text_to_speak(self, text, output_file): + request_json = { + "model": self.model, + "input": text, + "voice": self.voice, + "response_format": self.response_format, + } + headers = { + "Authorization": f"Bearer {self.access_token}", + "Content-Type": "application/json" + } + response = requests.request("POST", self.api_url, json=request_json, headers=headers) + data = response.content + file_to_save = open(output_file, "wb") + file_to_save.write(data) From 1384652dd93eff39383ee2ac5ca2f6d6d2c41432 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 15 Feb 2025 09:56:24 +0800 Subject: [PATCH 2/5] no message --- core/providers/tts/siliconflow.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 core/providers/tts/siliconflow.py diff --git a/core/providers/tts/siliconflow.py b/core/providers/tts/siliconflow.py new file mode 100644 index 00000000..faca4405 --- /dev/null +++ b/core/providers/tts/siliconflow.py @@ -0,0 +1,41 @@ +import os +import uuid +import json +import base64 +import requests +from datetime import datetime +from core.providers.tts.base import TTSProviderBase + + +class TTSProvider(TTSProviderBase): + def __init__(self, config, delete_audio_file): + super().__init__(config, delete_audio_file) + self.model = config.get("model") + self.access_token = config.get("access_token") + self.voice = config.get("voice") + self.response_format = config.get("response_format") + self.sample_rate = config.get("sample_rate") + self.speed = config.get("speed") + self.gain = config.get("gain") + + self.host = "api.siliconflow.cn" + self.api_url = f"https://{self.host}/v1/audio/speech" + + def generate_filename(self, extension=".wav"): + return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}") + + async def text_to_speak(self, text, output_file): + request_json = { + "model": self.model, + "input": text, + "voice": self.voice, + "response_format": self.response_format, + } + headers = { + "Authorization": f"Bearer {self.access_token}", + "Content-Type": "application/json" + } + response = requests.request("POST", self.api_url, json=request_json, headers=headers) + data = response.content + file_to_save = open(output_file, "wb") + file_to_save.write(data) From d45be0259b1e1268b666c3bb76c309633169505c Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 15 Feb 2025 10:01:50 +0800 Subject: [PATCH 3/5] =?UTF-8?q?update=EF=BC=9A=E7=A7=BB=E9=99=A4=E6=B5=8B?= =?UTF-8?q?=E8=AF=95token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 30de0453..391042ce 100644 --- a/config.yaml +++ b/config.yaml @@ -82,7 +82,7 @@ LLM: # 可在这里找到你的api key https://bigmodel.cn/usercenter/proj-mgmt/apikeys model_name: glm-4-flash url: https://open.bigmodel.cn/api/paas/v4/ - api_key: 47ab8569b25f4c3d8ea25830a33a64ca.4cF037cViBB1df5o + api_key: 你的chat-glm api key OllamaLLM: # 定义LLM API类型 type: ollama From 0c554b00ec41358f96c7a5e5894924531f1674cd Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 15 Feb 2025 10:20:57 +0800 Subject: [PATCH 4/5] no message --- config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.yaml b/config.yaml index 391042ce..7f82f47f 100644 --- a/config.yaml +++ b/config.yaml @@ -118,7 +118,7 @@ TTS: appid: 你的火山引擎语音合成服务appid access_token: 你的火山引擎语音合成服务access_token cluster: volcano_tts -CosyVoiceSiliconflow: + CosyVoiceSiliconflow: type: siliconflow model: FunAudioLLM/CosyVoice2-0.5B voice: FunAudioLLM/CosyVoice2-0.5B:alex From 7d30ddd66038ed030bdb5aeee117cbbc33d8d92b Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 15 Feb 2025 11:05:18 +0800 Subject: [PATCH 5/5] =?UTF-8?q?update:=E4=BC=98=E5=8C=96gemini=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 6 ++++++ core/utils/llm.py | 4 ---- requirements.txt | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index 7f82f47f..7a9aebce 100644 --- a/config.yaml +++ b/config.yaml @@ -97,6 +97,10 @@ LLM: api_key: 你的DifyLLM api key GeminiLLM: type: gemini + # 谷歌Gemini API,需要先在Google Cloud控制台创建API密钥并获取api_key + # 若在中国境内使用,请遵守《生成式人工智能服务管理暂行办法》 + # token申请地址: https://aistudio.google.com/apikey + # 若部署地无法访问接口,需要开启科学上网 api_key: 你的gemini api key model_name: "gemini-1.5-pro" # gemini-1.5-pro 是免费的 TTS: @@ -120,6 +124,8 @@ TTS: cluster: volcano_tts CosyVoiceSiliconflow: type: siliconflow + # 硅基流动TTS + # token申请地址 https://cloud.siliconflow.cn/account/ak model: FunAudioLLM/CosyVoice2-0.5B voice: FunAudioLLM/CosyVoice2-0.5B:alex output_file: tmp/ diff --git a/core/utils/llm.py b/core/utils/llm.py index 79b48dbb..1cdfcefb 100644 --- a/core/utils/llm.py +++ b/core/utils/llm.py @@ -1,15 +1,11 @@ import os import sys -import json import logging -import openai -import requests import importlib from datetime import datetime from core.utils.util import is_segment from core.utils.util import get_string_no_punctuation_or_emoji from core.utils.util import read_config, get_project_dir -from abc import ABC, abstractmethod logger = logging.getLogger(__name__) diff --git a/requirements.txt b/requirements.txt index 2e69445e..9fa53a9c 100755 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ torchaudio==2.2.2 openai==1.61.0 google-generativeai==0.8.4 edge_tts==7.0.0 -httpx==0.27.2 \ No newline at end of file +httpx==0.27.2 +google-generativeai==0.8.4 \ No newline at end of file