fcyai/ChatTTS-Story-Telling
1
1# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import re15 16from .num import verbalize_digit17 18# 规范化固话/手机号码19# 手机20# http://www.jihaoba.com/news/show/1368021# 移动:139、138、137、136、135、134、159、158、157、150、151、152、188、187、182、183、184、178、19822# 联通:130、131、132、156、155、186、185、17623# 电信:133、153、189、180、181、17724RE_MOBILE_PHONE = re.compile(25 r"(?<!\d)((\+?86 ?)?1([38]\d|5[0-35-9]|7[678]|9[89])\d{8})(?!\d)")26RE_TELEPHONE = re.compile(27 r"(?<!\d)((0(10|2[1-3]|[3-9]\d{2})-?)?[1-9]\d{7,8})(?!\d)")28 29# 全国统一的号码400开头30RE_NATIONAL_UNIFORM_NUMBER = re.compile(r"(400)(-)?\d{3}(-)?\d{4}")31 32 33def phone2str(phone_string: str, mobile=True) -> str:34 if mobile:35 sp_parts = phone_string.strip('+').split()36 result = ','.join(37 [verbalize_digit(part, alt_one=True) for part in sp_parts])38 return result39 else:40 sil_parts = phone_string.split('-')41 result = ','.join(42 [verbalize_digit(part, alt_one=True) for part in sil_parts])43 return result44 45 46def replace_phone(match) -> str:47 """48 Args:49 match (re.Match)50 Returns:51 str52 """53 return phone2str(match.group(0), mobile=False)54 55 56def replace_mobile(match) -> str:57 """58 Args:59 match (re.Match)60 Returns:61 str62 """63 return phone2str(match.group(0))64 