mirror of
https://github.com/idootop/mi-gpt.git
synced 2024-09-20 06:45:38 +00:00
chore: 移除 TTS 不发音字符(emoji)
This commit is contained in:
parent
f88f05a920
commit
c7e1edbb6d
|
@ -12,7 +12,7 @@
|
|||
|
||||
- 登录凭证过期后自动刷新 token https://github.com/idootop/mi-gpt/issues/76
|
||||
- ✅ 优化网络请求错误重试策略(消息/播放状态轮询)
|
||||
- 移除 TTS 不发音字符(emoji)
|
||||
- ✅ 移除 TTS 不发音字符(emoji)
|
||||
|
||||
## 📚 文档
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { sleep } from "../../utils/base";
|
||||
import { removeEmojis } from "../../utils/string";
|
||||
|
||||
type ResponseStatus = "idle" | "responding" | "finished" | "canceled";
|
||||
|
||||
|
@ -47,13 +48,18 @@ export class StreamResponse {
|
|||
return this.status === "canceled";
|
||||
}
|
||||
|
||||
addResponse(text: string) {
|
||||
addResponse(_text: string) {
|
||||
if (this.status === "idle") {
|
||||
this.status = "responding";
|
||||
}
|
||||
if (this.status !== "responding") {
|
||||
return;
|
||||
}
|
||||
// 移除不发音字符(emoji)
|
||||
let text = removeEmojis(_text);
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
this._batchSubmit(text);
|
||||
}
|
||||
|
||||
|
|
|
@ -65,3 +65,12 @@ export function formatDateTime(date: Date) {
|
|||
|
||||
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除文字中的不发音字符(emoji)
|
||||
*/
|
||||
export function removeEmojis(text: string) {
|
||||
const emojiRegex =
|
||||
/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F1E0}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/gu;
|
||||
return text.replace(emojiRegex, "");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user