├── .gitignore ├── LICENSE ├── README.md └── main.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 asdMild 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # chinese-audio2face 2 | 中文到表情 3 | 中文转表情网上的信息不多,这个是自己总结的一部分, 4 | 5 | 关注一下bs2face_level_1和bs2face_level_2这两个变量, 6 | 如果是简单的,可以直接处理bs2face_level_2里面的口型,然后根据转换的结果找到对应的口型播放,需要美术再做一层提炼出来的音对应的connectAttr上层控制器。 7 | 中文全部的声母韵母处理涉及到40多个音,这个的主要作用是相似度高的合并到一起,参考了一些国内论文,不一定准确, 8 | 9 | def anaylise里面有一部是根据发音单元的排序省略不重要的音,这里只做了单个词的省略,实际情况的需要考虑前后词的weight,可以相对应去修改 10 | 11 | 关于时间戳的问题,这个涉及到语音识别的领域,识别出来每个字的时间戳再处理就可以了 12 | 13 | 依赖pypinyin 14 | pip install pypinyin 15 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from pypinyin import pinyin, lazy_pinyin, Style 2 | ''' 3 | shengmu_l = '玻坡摸佛得特讷勒哥科喝基欺希知吃诗日资雌思医屋' 4 | yunmu_l = '飘啊呀蛙喔哟窝鹅耶约哀厓歪诶威熬腰欧忧安烟弯冤恩因温晕昂央汪鞥英翁轰雍思儿也居略虚训允姐' 5 | shengmu_l = lazy_pinyin(shengmu_l, style=Style.INITIALS, strict=False) 6 | yunmu_l = lazy_pinyin(yunmu_l, style=Style.FINALS, strict=False) 7 | shengmu_l = list(set(shengmu_l)) 8 | yunmu_l = list(set(yunmu_l)) 9 | # print(shengmu_l) 10 | # print(yunmu_l) 11 | ''' 12 | 13 | shengmu_level = {0: ['b', 'p', 'm'], 14 | 1: ['f'], 15 | 2: ['d', 't', 'z', 'c', 's', 'n', 'l'], 16 | 3: ['zh', 'ch', 'sh', 'r'], 17 | 4: ['j', 'q', 'x'], 18 | 5: ['g', 'k', 'h'], 19 | 6: ['y', 'w'], } 20 | 21 | yunmu_level = {0: ['ai', 'an', 'a', 'ang', 'uan', 'ia', 'ua', 'uai', 'ian', 'iang', 'van', 'uang'], 22 | 1: ['ou', 'o', 'ao', 'iao', 'uo', 'iu'], 23 | 2: ['e', 'er', 'en', 'eng', 've'], 24 | 3: ['ei', 'ui'], 25 | 4: ['i', 'in', 'ing', 'ie'], 26 | 5: ['u', 'ong', 'iong'], 27 | 6: ['v', 'un', 'vn'],} 28 | 29 | shengmu2level = {} 30 | yunmu2level = {} 31 | for i, j in shengmu_level.items(): 32 | for k in j: 33 | shengmu2level[k] = i 34 | for i, j in yunmu_level.items(): 35 | for k in j: 36 | yunmu2level[k] = i 37 | 38 | 39 | all_code = ['b', 'p', 'm', 'f', 'd', 't', 'z', 'c', 's', 'n', 'l', 'zh', 'ch', 'sh', 40 | 'r', 'j', 'q', 'x', 'g', 'k', 'h', 'y', 'w', 'ai', 'an', 'a', 'ang', 'uan', 41 | 'ia', 'ua', 'uai', 'ian', 'iang', 'ou', 'o', 'ao', 'iao', 'uo', 42 | 'e', 'er', 'en', 'eng', 've', 43 | 'ei', 'i', 'in', 'ing', 'u', 'ong', 'iong', 'v', 'un', 'vn', 'van', 'ui', 'uang', 'ie', 'iu'] 44 | 45 | shengmu_similar = {'b': ['p', 'm'], # 波 46 | 'f': [], # 夫 47 | 'd': ['t', 'z', 'c', 's', 'n', 'l'], # 的 48 | 'zh': ['ch', 'sh', 'r'], # 知 49 | 'j': ['q', 'x'], # 鸡 50 | 'g': ['k', 'h'], # 鸽 51 | 'y': ['w'], # 无 52 | } 53 | 54 | yunmu_similar = {'a': ['ai', 'an', 'ang', 'uan', 'ia', 'ua', 'uai', 'ian', 'iang', 'van', 'uang'], # 啊 55 | 'ou': ['ao', 'o', 'iao', 'uo', 'iu'], # 欧 56 | 'e': ['er', 'en', 'eng', 've'], # 额 57 | 'ei': ['ui'], # 诶 58 | 'i': ['in', 'ing', 'ie'], # 一 59 | 'ong': ['u', 'iong'], # 工 60 | 'v': ['un', 'vn'], # 鱼 61 | } 62 | 63 | all_similar = {'b': [], # 波 64 | 'f': [], # 夫 65 | 'd': ['zh', 'j', 'g'], # 的知鸡鸽 66 | 'a': [], # 啊 67 | 'ou': [], # 欧 68 | 'e': ['ei'], # 额诶 69 | 'i': [], # 一 70 | 'v': ['y', 'ong'], # 鱼无工 71 | } 72 | 73 | bs2face_level_1 = {'b': '波', 74 | 'f': '夫', 75 | 'd': '的', 76 | 'zh': '知', 77 | 'j': '鸡', 78 | 'g': '鸽', 79 | 'y': '无', 80 | 'a': '啊', 81 | 'ou': '欧', 82 | 'e': '额', 83 | 'ei': '诶', 84 | 'i': '一', 85 | 'ong': '工', 86 | 'v': '鱼', } 87 | bs2face_level_2 = {'b': '波', 88 | 'f': '夫', 89 | 'd': '知', 90 | 'a': '啊', 91 | 'ou': '欧', 92 | 'e': '额', 93 | 'i': '一', 94 | 'v': '鱼', 95 | } 96 | 97 | # child to parent dict 98 | c_to_p_1 = {} 99 | c_to_p_2 = {} 100 | for i, j in shengmu_similar.items(): 101 | for k in j: 102 | if k in c_to_p_1.keys(): 103 | print('error: ', k) 104 | c_to_p_1[k] = i 105 | for i, j in yunmu_similar.items(): 106 | for k in j: 107 | if k in c_to_p_1.keys(): 108 | print('error: ', k) 109 | c_to_p_1[k] = i 110 | for i, j in all_similar.items(): 111 | for k in j: 112 | if k in c_to_p_2.keys(): 113 | print('error: ', k) 114 | c_to_p_2[k] = i 115 | 116 | 117 | def check_parent(in_code, lazy=True): 118 | return_code = in_code 119 | if in_code in c_to_p_1.keys(): 120 | return_code = c_to_p_1[in_code] 121 | if lazy: 122 | if return_code in c_to_p_2.keys(): 123 | return_code = c_to_p_2[return_code] 124 | if return_code in all_code: 125 | return return_code 126 | return '-1' + return_code 127 | 128 | 129 | def anaylise(shengmu, yunmu, d=2, lazy=True): 130 | sl = 100 131 | yl = 100 132 | if shengmu in shengmu2level.keys(): 133 | sl = shengmu2level[shengmu] 134 | if yunmu in yunmu2level.keys(): 135 | yl = yunmu2level[yunmu] 136 | if abs(sl-yl) > d: 137 | if sl > yl: 138 | return [check_parent(yunmu, lazy=lazy)] 139 | else: 140 | return [check_parent(shengmu, lazy=lazy)] 141 | else: 142 | return [check_parent(shengmu, lazy=lazy), check_parent(yunmu, lazy=lazy)] 143 | 144 | 145 | # test data 146 | try: 147 | if 1: 148 | pinyin_data = [] 149 | pinyin_data_lazy = [] 150 | data = '我在这里看到了你的姐姐晕倒在了鱼云之上' 151 | for i in data: 152 | py1 = lazy_pinyin(i, style=Style.INITIALS, strict=False) 153 | py2 = lazy_pinyin(i, style=Style.FINALS, strict=False) 154 | for p in range(len(py1)): 155 | if py1[p] in all_code or py2[p] in all_code: 156 | pinyin_data_lazy += [anaylise(py1[p], py2[p])] 157 | pinyin_data += [anaylise(py1[p], py2[p], lazy=False)] 158 | 159 | ay_lazy = [] 160 | ay = [] 161 | for i in pinyin_data_lazy: 162 | for j in i: 163 | if j in bs2face_level_2.keys(): 164 | ay_lazy.append(bs2face_level_2[j]) 165 | for i in pinyin_data: 166 | for j in i: 167 | if j in bs2face_level_1.keys(): 168 | ay.append(bs2face_level_1[j]) 169 | 170 | print('level 1 data:','-'*10) 171 | print(pinyin_data) 172 | print(ay) 173 | print('level 1 data:','-'*10) 174 | print('level 2 data:','-'*10) 175 | print(pinyin_data_lazy) 176 | print(ay_lazy) 177 | print('level 2 data:','-'*10) 178 | exit() 179 | except: 180 | pass 181 | --------------------------------------------------------------------------------