refactor: Refactor the get_all_azure_voices function to reduce the amount of code by half
This commit is contained in:
@@ -1014,27 +1014,20 @@ Name: zh-CN-XiaoxiaoMultilingualNeural-V2
|
|||||||
Gender: Female
|
Gender: Female
|
||||||
""".strip()
|
""".strip()
|
||||||
voices = []
|
voices = []
|
||||||
name = ""
|
# 定义正则表达式模式,用于匹配 Name 和 Gender 行
|
||||||
for line in voices_str.split("\n"):
|
pattern = re.compile(r"Name:\s*(.+)\s*Gender:\s*(.+)\s*", re.MULTILINE)
|
||||||
line = line.strip()
|
# 使用正则表达式查找所有匹配项
|
||||||
if not line:
|
matches = pattern.findall(voices_str)
|
||||||
continue
|
|
||||||
if line.startswith("Name: "):
|
for name, gender in matches:
|
||||||
name = line[6:].strip()
|
# 应用过滤条件
|
||||||
if line.startswith("Gender: "):
|
if filter_locals and any(
|
||||||
gender = line[8:].strip()
|
name.lower().startswith(fl.lower()) for fl in filter_locals
|
||||||
if name and gender:
|
):
|
||||||
# voices.append({
|
|
||||||
# "name": name,
|
|
||||||
# "gender": gender,
|
|
||||||
# })
|
|
||||||
if filter_locals:
|
|
||||||
for filter_local in filter_locals:
|
|
||||||
if name.lower().startswith(filter_local.lower()):
|
|
||||||
voices.append(f"{name}-{gender}")
|
voices.append(f"{name}-{gender}")
|
||||||
else:
|
elif not filter_locals:
|
||||||
voices.append(f"{name}-{gender}")
|
voices.append(f"{name}-{gender}")
|
||||||
name = ""
|
|
||||||
voices.sort()
|
voices.sort()
|
||||||
return voices
|
return voices
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user