mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
使用emoji库来检查表情
This commit is contained in:
parent
5401f3fe04
commit
c44550c27f
4 changed files with 30 additions and 14 deletions
|
|
@ -19,15 +19,12 @@ class TTSProvider(TTSProviderBase):
|
|||
"Authorization": f"Bearer {self.apikey}"
|
||||
}
|
||||
|
||||
def clean_emojis(self, text):
|
||||
return emoji.replace_emoji(text, '')
|
||||
|
||||
def generate_filename(self, extension=".mp3"):
|
||||
return os.path.join(self.output_file, f"tts-{__name__}{datetime.now().date()}@{uuid.uuid4().hex}{extension}")
|
||||
|
||||
async def text_to_speak(self, text, output_file):
|
||||
request_json = {
|
||||
"input": self.clean_emojis(text),
|
||||
"input": text,
|
||||
"voice": self.voice
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
import re
|
||||
import json
|
||||
import emoji
|
||||
import yaml
|
||||
import socket
|
||||
|
||||
|
|
@ -47,15 +48,17 @@ def is_punctuation_or_emoji(char):
|
|||
if char.isspace() or char in punctuation_set:
|
||||
return True
|
||||
# 检查表情符号(保留原有逻辑)
|
||||
code_point = ord(char)
|
||||
emoji_ranges = [
|
||||
(0x1F600, 0x1F64F), (0x1F300, 0x1F5FF),
|
||||
(0x1F680, 0x1F6FF), (0x1F900, 0x1F9FF),
|
||||
(0x1FA70, 0x1FAFF), (0x2600, 0x26FF),
|
||||
(0x2700, 0x27BF)
|
||||
]
|
||||
return any(start <= code_point <= end for start, end in emoji_ranges)
|
||||
|
||||
#code_point = ord(char)
|
||||
#emoji_ranges = [
|
||||
# (0x1F600, 0x1F64F), (0x1F300, 0x1F5FF),
|
||||
# (0x1F680, 0x1F6FF), (0x1F900, 0x1F9FF),
|
||||
# (0x1FA70, 0x1FAFF), (0x2600, 0x26FF),
|
||||
# (0x2700, 0x27BF)
|
||||
#]
|
||||
#return any(start <= code_point <= end for start, end in emoji_ranges)
|
||||
|
||||
# 使用emoji库来检查
|
||||
return emoji.emoji_count(char) > 0
|
||||
|
||||
def get_string_no_punctuation_or_emoji(s):
|
||||
"""去除字符串首尾的空格、标点符号和表情符号"""
|
||||
|
|
|
|||
17
poetry.lock
generated
17
poetry.lock
generated
|
|
@ -680,6 +680,21 @@ files = [
|
|||
{file = "editdistance-0.8.1.tar.gz", hash = "sha256:d1cdf80a5d5014b0c9126a69a42ce55a457b457f6986ff69ca98e4fe4d2d8fed"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "emoji"
|
||||
version = "2.14.1"
|
||||
description = "Emoji for Python"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "emoji-2.14.1-py3-none-any.whl", hash = "sha256:35a8a486c1460addb1499e3bf7929d3889b2e2841a57401903699fef595e942b"},
|
||||
{file = "emoji-2.14.1.tar.gz", hash = "sha256:f8c50043d79a2c1410ebfae833ae1868d5941a67a6cd4d18377e2eb0bd79346b"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
dev = ["coverage", "pytest (>=7.4.4)"]
|
||||
|
||||
[[package]]
|
||||
name = "exceptiongroup"
|
||||
version = "1.2.2"
|
||||
|
|
@ -3732,4 +3747,4 @@ propcache = ">=0.2.0"
|
|||
[metadata]
|
||||
lock-version = "2.1"
|
||||
python-versions = "^3.10.16"
|
||||
content-hash = "9d724dd1cc50a7a6a42f0b5d8a81ad788332939ffc6a3ba12537106567f4ebe7"
|
||||
content-hash = "8e08db186a6bd1139f23024ac7818e749db9c46df41281c8f3a22bb2a650bac6"
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ ruamel-yaml = "0.18.10"
|
|||
setuptools = "^75.8.0"
|
||||
loguru = "^0.7.3"
|
||||
opuslib-next = "^1.1.2"
|
||||
emoji = "2.14.1"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
|
|
|||
Loading…
Reference in a new issue