chore: 移除 TTS 不发音字符(emoji)

This commit is contained in:
WJG 2024-06-15 10:46:52 +08:00
parent f88f05a920
commit c7e1edbb6d
No known key found for this signature in database
GPG Key ID: 258474EF8590014A
3 changed files with 17 additions and 2 deletions

View File

@ -12,7 +12,7 @@
- 登录凭证过期后自动刷新 token https://github.com/idootop/mi-gpt/issues/76
- ✅ 优化网络请求错误重试策略(消息/播放状态轮询)
- 移除 TTS 不发音字符emoji
- 移除 TTS 不发音字符emoji
## 📚 文档

View File

@ -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);
}

View File

@ -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, "");
}