xiaogpt 2.63__tar.gz → 2.64__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {xiaogpt-2.63 → xiaogpt-2.64}/PKG-INFO +38 -38
  2. {xiaogpt-2.63 → xiaogpt-2.64}/README.md +35 -35
  3. {xiaogpt-2.63 → xiaogpt-2.64}/pyproject.toml +3 -3
  4. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/config.py +3 -1
  5. xiaogpt-2.64/xiaogpt/tts/tetos.py +31 -0
  6. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/xiaogpt.py +7 -1
  7. xiaogpt-2.63/xiaogpt/tts/tetos.py +0 -56
  8. {xiaogpt-2.63 → xiaogpt-2.64}/LICENSE +0 -0
  9. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/__init__.py +0 -0
  10. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/__main__.py +0 -0
  11. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/__init__.py +0 -0
  12. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/base_bot.py +0 -0
  13. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/chatgptapi_bot.py +0 -0
  14. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/doubao_bot.py +0 -0
  15. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/gemini_bot.py +0 -0
  16. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/glm_bot.py +0 -0
  17. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/langchain_bot.py +0 -0
  18. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/newbing_bot.py +0 -0
  19. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/bot/qwen_bot.py +0 -0
  20. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/cli.py +0 -0
  21. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/langchain/callbacks.py +0 -0
  22. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/langchain/chain.py +0 -0
  23. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/langchain/examples/email/mail_box.py +0 -0
  24. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/langchain/examples/email/mail_summary_tools.py +0 -0
  25. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/tts/__init__.py +0 -0
  26. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/tts/base.py +0 -0
  27. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/tts/mi.py +0 -0
  28. {xiaogpt-2.63 → xiaogpt-2.64}/xiaogpt/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xiaogpt
3
- Version: 2.63
3
+ Version: 2.64
4
4
  Summary: Play ChatGPT or other LLM with xiaomi AI speaker
5
5
  Author-Email: yihong0618 <zouzou0208@gmail.com>
6
6
  License: MIT
@@ -22,7 +22,7 @@ Requires-Dist: google-search-results>=2.4.2
22
22
  Requires-Dist: google-generativeai
23
23
  Requires-Dist: numexpr>=2.8.6
24
24
  Requires-Dist: dashscope>=1.10.0
25
- Requires-Dist: tetos>=0.1.1
25
+ Requires-Dist: tetos>=0.2.1
26
26
  Requires-Dist: aiohttp==3.9.5; extra == "locked"
27
27
  Requires-Dist: aiosignal==1.3.1; extra == "locked"
28
28
  Requires-Dist: annotated-types==0.6.0; extra == "locked"
@@ -102,7 +102,7 @@ Requires-Dist: socksio==1.0.0; extra == "locked"
102
102
  Requires-Dist: soupsieve==2.5; extra == "locked"
103
103
  Requires-Dist: sqlalchemy==2.0.25; extra == "locked"
104
104
  Requires-Dist: tenacity==8.2.3; extra == "locked"
105
- Requires-Dist: tetos==0.1.1; extra == "locked"
105
+ Requires-Dist: tetos==0.2.1; extra == "locked"
106
106
  Requires-Dist: tqdm==4.66.1; extra == "locked"
107
107
  Requires-Dist: typing-extensions==4.9.0; extra == "locked"
108
108
  Requires-Dist: typing-inspect==0.9.0; extra == "locked"
@@ -195,7 +195,7 @@ xiaogpt --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
195
195
  # 如果你想使用自己的 google gemini 服务
196
196
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key} --gemini_api_domain ${gemini_api_domain}
197
197
  # 如果你想使用阿里的通义千问
198
- xiaogpt --hardware LX06 --mute_xiaoai --use_qwen --qen_key ${qwen_key}
198
+ xiaogpt --hardware LX06 --mute_xiaoai --use_qwen --qwen_key ${qwen_key}
199
199
  # 如果你想使用豆包
200
200
  xiaogpt --hardware LX06 --mute_xiaoai --use_doubao --stream --volc_access_key xxxx --volc_secret_key xxx
201
201
  # 如果你想用 edge-tts
@@ -226,7 +226,7 @@ python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${ge
226
226
  # 如果你想使用自己的 google gemini 服务
227
227
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key} --gemini_api_domain ${gemini_api_domain}
228
228
  # 如果你想使用阿里的通义千问
229
- python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_qwen --qen_key ${qwen_key}
229
+ python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_qwen --qwen_key ${qwen_key}
230
230
  # 如果你想使用豆包
231
231
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_doubao --stream --volc_access_key xxxx --volc_secret_key xxx
232
232
  # 如果你想使用 LangChain+SerpApi 实现上网检索或其他本地服务(目前仅支持 stream 模式)
@@ -272,39 +272,39 @@ ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
272
272
 
273
273
  ## 配置项说明
274
274
 
275
- | 参数 | 说明 | 默认值 | 可选值 |
276
- | --------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
277
- | hardware | 设备型号 | | |
278
- | account | 小爱账户 | | |
279
- | password | 小爱账户密码 | | |
280
- | openai_key | openai的apikey | | |
281
- | serpapi_api_key | serpapi的key 参考 [SerpAPI](https://serpapi.com/) | | |
282
- | glm_key | chatglm 的 apikey | | |
283
- | gemini_key | gemini 的 apikey [参考](https://makersuite.google.com/app/apikey) | | |
284
- | gemini_api_domain | gemini 的自定义域名 [参考](https://github.com/antergone/palm-netlify-proxy) | |
285
- | qwen_key | qwen 的 apikey [参考](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) | | |
286
- | cookie | 小爱账户cookie (如果用上面密码登录可以不填) | | |
287
- | mi_did | 设备did | | |
288
- | use_command | 使用 MI command 与小爱交互 | `false` | |
289
- | mute_xiaoai | 快速停掉小爱自己的回答 | `true` | |
290
- | verbose | 是否打印详细日志 | `false` | |
291
- | bot | 使用的 bot 类型,目前支持 chatgptapi,newbing, qwen, gemini | `chatgptapi` | |
292
- | tts | 使用的 TTS 类型 | `mi` | `edge`、 `openai`、`azure`、`volc`、`baidu`、`google` |
293
- | tts_options | TTS 参数字典,参考 [tetos](https://github.com/frostming/tetos) 获取可用参数 | | |
294
- | prompt | 自定义prompt | `请用100字以内回答` | |
295
- | keyword | 自定义请求词列表 | `["请"]` | |
296
- | change_prompt_keyword | 更改提示词触发列表 | `["更改提示词"]` | |
297
- | start_conversation | 开始持续对话关键词 | `开始持续对话` | |
298
- | end_conversation | 结束持续对话关键词 | `结束持续对话` | |
299
- | stream | 使用流式响应,获得更快的响应 | `false` | |
300
- | proxy | 支持 HTTP 代理,传入 http proxy URL | "" | |
301
- | gpt_options | OpenAI API 的参数字典 | `{}` | |
302
- | bing_cookie_path | NewBing使用的cookie路径,参考[这里]获取 | 也可通过环境变量 `COOKIE_FILE` 设置 | |
303
- | bing_cookies | NewBing使用的cookie字典,参考[这里]获取 | | |
304
- | deployment_id | Azure OpenAI 服务的 deployment ID | 参考这个[如何找到deployment_id](https://github.com/yihong0618/xiaogpt/issues/347#issuecomment-1784410784) | |
305
- | api_base | 如果需要替换默认的api,或者使用Azure OpenAI 服务 | 例如:`https://abc-def.openai.azure.com/` |
306
- | volc_access_key | 火山引擎的 access key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
307
- | volc_secret_key | 火山引擎的 secret key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
275
+ | 参数 | 说明 | 默认值 | 可选值 |
276
+ | --------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
277
+ | hardware | 设备型号 | | |
278
+ | account | 小爱账户 | | |
279
+ | password | 小爱账户密码 | | |
280
+ | openai_key | openai的apikey | | |
281
+ | serpapi_api_key | serpapi的key 参考 [SerpAPI](https://serpapi.com/) | | |
282
+ | glm_key | chatglm 的 apikey | | |
283
+ | gemini_key | gemini 的 apikey [参考](https://makersuite.google.com/app/apikey) | | |
284
+ | gemini_api_domain | gemini 的自定义域名 [参考](https://github.com/antergone/palm-netlify-proxy) | |
285
+ | qwen_key | qwen 的 apikey [参考](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) | | |
286
+ | cookie | 小爱账户cookie (如果用上面密码登录可以不填) | | |
287
+ | mi_did | 设备did | | |
288
+ | use_command | 使用 MI command 与小爱交互 | `false` | |
289
+ | mute_xiaoai | 快速停掉小爱自己的回答 | `true` | |
290
+ | verbose | 是否打印详细日志 | `false` | |
291
+ | bot | 使用的 bot 类型,目前支持 chatgptapi,newbing, qwen, gemini | `chatgptapi` | |
292
+ | tts | 使用的 TTS 类型 | `mi` | `edge`、 `openai`、`azure`、`volc`、`baidu`、`google`、`minimax` |
293
+ | tts_options | TTS 参数字典,参考 [tetos](https://github.com/frostming/tetos) 获取可用参数 | | |
294
+ | prompt | 自定义prompt | `请用100字以内回答` | |
295
+ | keyword | 自定义请求词列表 | `["请"]` | |
296
+ | change_prompt_keyword | 更改提示词触发列表 | `["更改提示词"]` | |
297
+ | start_conversation | 开始持续对话关键词 | `开始持续对话` | |
298
+ | end_conversation | 结束持续对话关键词 | `结束持续对话` | |
299
+ | stream | 使用流式响应,获得更快的响应 | `false` | |
300
+ | proxy | 支持 HTTP 代理,传入 http proxy URL | "" | |
301
+ | gpt_options | OpenAI API 的参数字典 | `{}` | |
302
+ | bing_cookie_path | NewBing使用的cookie路径,参考[这里]获取 | 也可通过环境变量 `COOKIE_FILE` 设置 | |
303
+ | bing_cookies | NewBing使用的cookie字典,参考[这里]获取 | | |
304
+ | deployment_id | Azure OpenAI 服务的 deployment ID | 参考这个[如何找到deployment_id](https://github.com/yihong0618/xiaogpt/issues/347#issuecomment-1784410784) | |
305
+ | api_base | 如果需要替换默认的api,或者使用Azure OpenAI 服务 | 例如:`https://abc-def.openai.azure.com/` |
306
+ | volc_access_key | 火山引擎的 access key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
307
+ | volc_secret_key | 火山引擎的 secret key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
308
308
  [这里]: https://github.com/acheong08/EdgeGPT#getting-authentication-required
309
309
 
310
310
  ## 注意
@@ -78,7 +78,7 @@ xiaogpt --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key}
78
78
  # 如果你想使用自己的 google gemini 服务
79
79
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key} --gemini_api_domain ${gemini_api_domain}
80
80
  # 如果你想使用阿里的通义千问
81
- xiaogpt --hardware LX06 --mute_xiaoai --use_qwen --qen_key ${qwen_key}
81
+ xiaogpt --hardware LX06 --mute_xiaoai --use_qwen --qwen_key ${qwen_key}
82
82
  # 如果你想使用豆包
83
83
  xiaogpt --hardware LX06 --mute_xiaoai --use_doubao --stream --volc_access_key xxxx --volc_secret_key xxx
84
84
  # 如果你想用 edge-tts
@@ -109,7 +109,7 @@ python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${ge
109
109
  # 如果你想使用自己的 google gemini 服务
110
110
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_gemini --gemini_key ${gemini_key} --gemini_api_domain ${gemini_api_domain}
111
111
  # 如果你想使用阿里的通义千问
112
- python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_qwen --qen_key ${qwen_key}
112
+ python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_qwen --qwen_key ${qwen_key}
113
113
  # 如果你想使用豆包
114
114
  python3 xiaogpt.py --hardware LX06 --mute_xiaoai --use_doubao --stream --volc_access_key xxxx --volc_secret_key xxx
115
115
  # 如果你想使用 LangChain+SerpApi 实现上网检索或其他本地服务(目前仅支持 stream 模式)
@@ -155,39 +155,39 @@ ChatGLM [文档](http://open.bigmodel.cn/doc/api#chatglm_130b)
155
155
 
156
156
  ## 配置项说明
157
157
 
158
- | 参数 | 说明 | 默认值 | 可选值 |
159
- | --------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
160
- | hardware | 设备型号 | | |
161
- | account | 小爱账户 | | |
162
- | password | 小爱账户密码 | | |
163
- | openai_key | openai的apikey | | |
164
- | serpapi_api_key | serpapi的key 参考 [SerpAPI](https://serpapi.com/) | | |
165
- | glm_key | chatglm 的 apikey | | |
166
- | gemini_key | gemini 的 apikey [参考](https://makersuite.google.com/app/apikey) | | |
167
- | gemini_api_domain | gemini 的自定义域名 [参考](https://github.com/antergone/palm-netlify-proxy) | |
168
- | qwen_key | qwen 的 apikey [参考](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) | | |
169
- | cookie | 小爱账户cookie (如果用上面密码登录可以不填) | | |
170
- | mi_did | 设备did | | |
171
- | use_command | 使用 MI command 与小爱交互 | `false` | |
172
- | mute_xiaoai | 快速停掉小爱自己的回答 | `true` | |
173
- | verbose | 是否打印详细日志 | `false` | |
174
- | bot | 使用的 bot 类型,目前支持 chatgptapi,newbing, qwen, gemini | `chatgptapi` | |
175
- | tts | 使用的 TTS 类型 | `mi` | `edge`、 `openai`、`azure`、`volc`、`baidu`、`google` |
176
- | tts_options | TTS 参数字典,参考 [tetos](https://github.com/frostming/tetos) 获取可用参数 | | |
177
- | prompt | 自定义prompt | `请用100字以内回答` | |
178
- | keyword | 自定义请求词列表 | `["请"]` | |
179
- | change_prompt_keyword | 更改提示词触发列表 | `["更改提示词"]` | |
180
- | start_conversation | 开始持续对话关键词 | `开始持续对话` | |
181
- | end_conversation | 结束持续对话关键词 | `结束持续对话` | |
182
- | stream | 使用流式响应,获得更快的响应 | `false` | |
183
- | proxy | 支持 HTTP 代理,传入 http proxy URL | "" | |
184
- | gpt_options | OpenAI API 的参数字典 | `{}` | |
185
- | bing_cookie_path | NewBing使用的cookie路径,参考[这里]获取 | 也可通过环境变量 `COOKIE_FILE` 设置 | |
186
- | bing_cookies | NewBing使用的cookie字典,参考[这里]获取 | | |
187
- | deployment_id | Azure OpenAI 服务的 deployment ID | 参考这个[如何找到deployment_id](https://github.com/yihong0618/xiaogpt/issues/347#issuecomment-1784410784) | |
188
- | api_base | 如果需要替换默认的api,或者使用Azure OpenAI 服务 | 例如:`https://abc-def.openai.azure.com/` |
189
- | volc_access_key | 火山引擎的 access key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
190
- | volc_secret_key | 火山引擎的 secret key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
158
+ | 参数 | 说明 | 默认值 | 可选值 |
159
+ | --------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
160
+ | hardware | 设备型号 | | |
161
+ | account | 小爱账户 | | |
162
+ | password | 小爱账户密码 | | |
163
+ | openai_key | openai的apikey | | |
164
+ | serpapi_api_key | serpapi的key 参考 [SerpAPI](https://serpapi.com/) | | |
165
+ | glm_key | chatglm 的 apikey | | |
166
+ | gemini_key | gemini 的 apikey [参考](https://makersuite.google.com/app/apikey) | | |
167
+ | gemini_api_domain | gemini 的自定义域名 [参考](https://github.com/antergone/palm-netlify-proxy) | |
168
+ | qwen_key | qwen 的 apikey [参考](https://help.aliyun.com/zh/dashscope/developer-reference/api-details) | | |
169
+ | cookie | 小爱账户cookie (如果用上面密码登录可以不填) | | |
170
+ | mi_did | 设备did | | |
171
+ | use_command | 使用 MI command 与小爱交互 | `false` | |
172
+ | mute_xiaoai | 快速停掉小爱自己的回答 | `true` | |
173
+ | verbose | 是否打印详细日志 | `false` | |
174
+ | bot | 使用的 bot 类型,目前支持 chatgptapi,newbing, qwen, gemini | `chatgptapi` | |
175
+ | tts | 使用的 TTS 类型 | `mi` | `edge`、 `openai`、`azure`、`volc`、`baidu`、`google`、`minimax` |
176
+ | tts_options | TTS 参数字典,参考 [tetos](https://github.com/frostming/tetos) 获取可用参数 | | |
177
+ | prompt | 自定义prompt | `请用100字以内回答` | |
178
+ | keyword | 自定义请求词列表 | `["请"]` | |
179
+ | change_prompt_keyword | 更改提示词触发列表 | `["更改提示词"]` | |
180
+ | start_conversation | 开始持续对话关键词 | `开始持续对话` | |
181
+ | end_conversation | 结束持续对话关键词 | `结束持续对话` | |
182
+ | stream | 使用流式响应,获得更快的响应 | `false` | |
183
+ | proxy | 支持 HTTP 代理,传入 http proxy URL | "" | |
184
+ | gpt_options | OpenAI API 的参数字典 | `{}` | |
185
+ | bing_cookie_path | NewBing使用的cookie路径,参考[这里]获取 | 也可通过环境变量 `COOKIE_FILE` 设置 | |
186
+ | bing_cookies | NewBing使用的cookie字典,参考[这里]获取 | | |
187
+ | deployment_id | Azure OpenAI 服务的 deployment ID | 参考这个[如何找到deployment_id](https://github.com/yihong0618/xiaogpt/issues/347#issuecomment-1784410784) | |
188
+ | api_base | 如果需要替换默认的api,或者使用Azure OpenAI 服务 | 例如:`https://abc-def.openai.azure.com/` |
189
+ | volc_access_key | 火山引擎的 access key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
190
+ | volc_secret_key | 火山引擎的 secret key 请在[这里](https://console.volcengine.com/iam/keymanage/)获取 | | |
191
191
  [这里]: https://github.com/acheong08/EdgeGPT#getting-authentication-required
192
192
 
193
193
  ## 注意
@@ -25,10 +25,10 @@ dependencies = [
25
25
  "google-generativeai",
26
26
  "numexpr>=2.8.6",
27
27
  "dashscope>=1.10.0",
28
- "tetos>=0.1.1",
28
+ "tetos>=0.2.1",
29
29
  ]
30
30
  dynamic = []
31
- version = "2.63"
31
+ version = "2.64"
32
32
 
33
33
  [project.license]
34
34
  text = "MIT"
@@ -120,7 +120,7 @@ locked = [
120
120
  "soupsieve==2.5",
121
121
  "sqlalchemy==2.0.25",
122
122
  "tenacity==8.2.3",
123
- "tetos==0.1.1",
123
+ "tetos==0.2.1",
124
124
  "tqdm==4.66.1",
125
125
  "typing-extensions==4.9.0",
126
126
  "typing-inspect==0.9.0",
@@ -76,7 +76,9 @@ class Config:
76
76
  start_conversation: str = "开始持续对话"
77
77
  end_conversation: str = "结束持续对话"
78
78
  stream: bool = False
79
- tts: Literal["mi", "edge", "azure", "openai", "baidu", "google", "volc"] = "mi"
79
+ tts: Literal[
80
+ "mi", "edge", "azure", "openai", "baidu", "google", "volc", "minimax"
81
+ ] = "mi"
80
82
  tts_options: dict[str, Any] = field(default_factory=dict)
81
83
  gpt_options: dict[str, Any] = field(default_factory=dict)
82
84
  bing_cookie_path: str = ""
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ import tempfile
4
+ from pathlib import Path
5
+
6
+ from miservice import MiNAService
7
+
8
+ from xiaogpt.config import Config
9
+ from xiaogpt.tts.base import AudioFileTTS
10
+
11
+
12
+ class TetosTTS(AudioFileTTS):
13
+ def __init__(
14
+ self, mina_service: MiNAService, device_id: str, config: Config
15
+ ) -> None:
16
+ from tetos import get_speaker
17
+
18
+ super().__init__(mina_service, device_id, config)
19
+ assert config.tts and config.tts != "mi"
20
+ speaker_cls = get_speaker(config.tts)
21
+ try:
22
+ self.speaker = speaker_cls(**config.tts_options)
23
+ except TypeError as e:
24
+ raise ValueError(f"{e}. Please add them via `tts_options` config") from e
25
+
26
+ async def make_audio_file(self, lang: str, text: str) -> tuple[Path, float]:
27
+ output_file = tempfile.NamedTemporaryFile(
28
+ suffix=".mp3", mode="wb", delete=False, dir=self.dirname.name
29
+ )
30
+ duration = await self.speaker.synthesize(text, output_file.name, lang=lang)
31
+ return Path(output_file.name), duration
@@ -418,9 +418,15 @@ class MiGPT:
418
418
  # It is not a legal language code, discard it
419
419
  lang, first_chunk = "", text
420
420
 
421
+ lang = (
422
+ matches[0]
423
+ if (matches := re.findall(r"([a-z]{2}-[A-Z]{2})", lang))
424
+ else "zh-CN"
425
+ )
426
+
421
427
  async def gen(): # reconstruct the generator
422
428
  yield first_chunk
423
429
  async for text in text_stream:
424
430
  yield text
425
431
 
426
- await self.tts.synthesize(lang or "zh-CN", gen())
432
+ await self.tts.synthesize(lang, gen())
@@ -1,56 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import tempfile
4
- from pathlib import Path
5
-
6
- from miservice import MiNAService
7
- from tetos.base import Speaker
8
-
9
- from xiaogpt.config import Config
10
- from xiaogpt.tts.base import AudioFileTTS
11
-
12
-
13
- class TetosTTS(AudioFileTTS):
14
- def __init__(
15
- self, mina_service: MiNAService, device_id: str, config: Config
16
- ) -> None:
17
- super().__init__(mina_service, device_id, config)
18
- self.speaker = self._get_speaker()
19
-
20
- def _get_speaker(self) -> Speaker:
21
- from tetos.azure import AzureSpeaker
22
- from tetos.baidu import BaiduSpeaker
23
- from tetos.edge import EdgeSpeaker
24
- from tetos.google import GoogleSpeaker
25
- from tetos.openai import OpenAISpeaker
26
- from tetos.volc import VolcSpeaker
27
-
28
- options = self.config.tts_options
29
- allowed_speakers: list[str] = []
30
- for speaker in (
31
- OpenAISpeaker,
32
- EdgeSpeaker,
33
- AzureSpeaker,
34
- VolcSpeaker,
35
- GoogleSpeaker,
36
- BaiduSpeaker,
37
- ):
38
- if (name := speaker.__name__[:-7].lower()) == self.config.tts:
39
- try:
40
- return speaker(**options)
41
- except TypeError as e:
42
- raise ValueError(
43
- f"{e}. Please add them via `tts_options` config"
44
- ) from e
45
- else:
46
- allowed_speakers.append(name)
47
- raise ValueError(
48
- f"Unsupported TTS: {self.config.tts}, allowed: {','.join(allowed_speakers)}"
49
- )
50
-
51
- async def make_audio_file(self, lang: str, text: str) -> tuple[Path, float]:
52
- output_file = tempfile.NamedTemporaryFile(
53
- suffix=".mp3", mode="wb", delete=False, dir=self.dirname.name
54
- )
55
- duration = await self.speaker.synthesize(text, output_file.name, lang=lang)
56
- return Path(output_file.name), duration
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes