├── .gitignore ├── LICENSE ├── README.md ├── main.py ├── misc_7z ├── misc.7z.001 ├── misc.7z.002 ├── misc.7z.003 ├── misc.7z.004 ├── misc.7z.005 ├── misc.7z.006 ├── misc.7z.007 └── misc.7z.008 ├── reliance ├── core.py ├── global_vars.py ├── imitation │ ├── audioTools.py │ ├── humanConverter.py │ ├── imitation.py │ ├── mfaDealer.py │ ├── play.py │ ├── praatDealer.py │ ├── sppasDealer.py │ ├── tts.py │ └── voiceAnaysis │ │ ├── analyzer.py │ │ └── utils.py ├── interface │ ├── commandline.py │ └── gui.py ├── output │ ├── dub.py │ ├── svpWrite.py │ └── vsqxWrite.py ├── sentManager.py ├── sentSeg.py └── tyTalk │ ├── talker.py │ └── talkerReliance │ ├── arabToChi.py │ ├── baiduCleint.py │ ├── pyCorrect.py │ ├── semanticEncoder.py │ └── vocalDict.py ├── requirements.txt ├── setup.bat └── setup_install ├── PyAudio-0.2.11-cp38-cp38-win_amd64.whl ├── huaweicloud-python-sdk-sis-1.7.1 ├── build │ └── lib │ │ └── huaweicloud_sis │ │ ├── __init__.py │ │ ├── auth │ │ ├── __init__.py │ │ ├── aksk_service.py │ │ ├── signer.py │ │ └── token_service.py │ │ ├── bean │ │ ├── __init__.py │ │ ├── asr_request.py │ │ ├── callback.py │ │ ├── flash_lasr_request.py │ │ ├── hot_word_request.py │ │ ├── pa_request.py │ │ ├── rasr_request.py │ │ ├── rtts_request.py │ │ ├── sis_config.py │ │ └── tts_request.py │ │ ├── client │ │ ├── __init__.py │ │ ├── asr_client.py │ │ ├── flash_lasr_client.py │ │ ├── hot_word_client.py │ │ ├── pa_client.py │ │ ├── rasr_client.py │ │ ├── rtts_client.py │ │ └── tts_client.py │ │ ├── exception │ │ ├── __init__.py │ │ └── exceptions.py │ │ └── utils │ │ ├── __init__.py │ │ ├── http_utils.py │ │ ├── io_utils.py │ │ └── logger_utils.py ├── cn_demo │ ├── flash_lasr_demo.py │ ├── hot_word_demo.py │ ├── lasr_demo.py │ ├── pa_demo.py │ ├── rasr_demo.py │ ├── sasr_demo.py │ ├── sasr_websocket_demo.py │ └── tts_demo.py ├── data │ ├── chinese │ │ ├── 16k.pcm │ │ ├── 16k.wav │ │ ├── 8k.pcm │ │ └── 8k.wav │ └── english │ │ ├── 16k.pcm │ │ ├── 16k.wav │ │ ├── 8k.pcm │ │ └── 8k.wav ├── dist │ └── huaweicloud_python_sdk_sis-1.7.1-py3.8.egg ├── huaweicloud_python_sdk_sis.egg-info │ ├── PKG-INFO │ ├── SOURCES.txt │ ├── dependency_links.txt │ ├── not-zip-safe │ ├── requires.txt │ └── top_level.txt ├── huaweicloud_sis │ ├── __init__.py │ ├── auth │ │ ├── __init__.py │ │ ├── aksk_service.py │ │ ├── signer.py │ │ └── token_service.py │ ├── bean │ │ ├── __init__.py │ │ ├── asr_request.py │ │ ├── callback.py │ │ ├── flash_lasr_request.py │ │ ├── hot_word_request.py │ │ ├── pa_request.py │ │ ├── rasr_request.py │ │ ├── rtts_request.py │ │ ├── sis_config.py │ │ └── tts_request.py │ ├── client │ │ ├── __init__.py │ │ ├── asr_client.py │ │ ├── flash_lasr_client.py │ │ ├── hot_word_client.py │ │ ├── pa_client.py │ │ ├── rasr_client.py │ │ ├── rtts_client.py │ │ └── tts_client.py │ ├── exception │ │ ├── __init__.py │ │ └── exceptions.py │ └── utils │ │ ├── __init__.py │ │ ├── http_utils.py │ │ ├── io_utils.py │ │ └── logger_utils.py ├── intl_demo │ └── asr_customization_demo.py ├── readme_cn.txt ├── readme_en.txt └── setup.py └── montreal_forced_aligner └── corpus └── acoustic_corpus.py /.gitignore: -------------------------------------------------------------------------------- 1 | /misc/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The code is distributed under Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0). 2 | 3 | The core point is that the code and its derivatives is not allowed to be used commertially except specially permitted. 4 | The details can be found in https://creativecommons.org/licenses/by-nc-sa/4.0/ 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VvTalk 2 | Tool for virtual vocalist talkoid in Mandarin. 汉语普通话语调教辅助工具。 3 | 4 | 版本号:1.0.1 5 | 6 | 打包好的版本可以在[b站专栏](https://space.bilibili.com/15114289/article)找到度盘链接,同时在[vsqx.top](https://www.vsqx.top/)上配布。 7 | 8 | 手动构建环境: 9 | 10 | 1. 安装MiniConda 11 | 12 | 2. 创建一个虚拟环境并激活 13 | 14 | ``` 15 | conda create -n VvTalk python=3.8 16 | 17 | conda activate VvTalk 18 | ``` 19 | 20 | 3. 确保终端的工作目录在项目的根目录后,运行setup.py 21 | 22 | `setup.py` 23 | 24 | 4. 下载 misc_7z 中的分卷压缩包,将 misc 文件夹解压到项目的根目录 25 | 26 | 5. 若安装完成后的使用过程中,在自动对齐时报错并对齐失败,可能是因为Montreal-Forced-Aligner的一个已经修复但尚未更新漏洞。查看其版本,若为2.0.0rc5,则将本项目中 setup_install/Monteral-Forced-Aligner/corpus/acoustic_corpus.py 文件替换掉对应目录下原有的文件,可以解决这个bug。 27 | 28 | 29 | 之前开源的[TyTalk](https://github.com/GalaxieT/TyTalk)算法对应本项目中的reliance.tyTalk 30 | 31 | 32 | 编程太难了555 33 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import reliance.global_vars 2 | 3 | VERSION = '1.0.1' 4 | VERSION_NO = 13 5 | 6 | reliance.global_vars.VERSION = VERSION 7 | reliance.global_vars.VERSION_NO = VERSION_NO 8 | 9 | if __name__ == "__main__": 10 | 11 | import multiprocessing 12 | import os 13 | import reliance.core 14 | import reliance.interface.commandline 15 | 16 | run_gui = reliance.interface.commandline.parse_interface() 17 | 18 | multiprocessing.freeze_support() 19 | 20 | if run_gui: 21 | run = True 22 | try: 23 | os.remove('misc\\temp\\lock') 24 | except PermissionError: 25 | print('重复调用,不启动') 26 | run = False 27 | except FileNotFoundError: 28 | pass 29 | if run: 30 | guard = open('misc\\temp\\lock', 'w') 31 | print('正在启动程序,请最小化本窗口,操作期间勿直接关闭本窗口,会随主窗口关闭而关闭') 32 | import reliance.interface.gui 33 | talk_core = reliance.core.core() 34 | reliance.interface.gui.tkinter_gui(talk_core) 35 | else: 36 | talk_core = reliance.core.core(no_projects=True) 37 | cmd_ui = reliance.interface.commandline.CmdUI(talk_core) 38 | cmd_ui.execute_command() 39 | 40 | -------------------------------------------------------------------------------- /misc_7z/misc.7z.001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.001 -------------------------------------------------------------------------------- /misc_7z/misc.7z.002: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.002 -------------------------------------------------------------------------------- /misc_7z/misc.7z.003: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.003 -------------------------------------------------------------------------------- /misc_7z/misc.7z.004: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.004 -------------------------------------------------------------------------------- /misc_7z/misc.7z.005: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.005 -------------------------------------------------------------------------------- /misc_7z/misc.7z.006: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.006 -------------------------------------------------------------------------------- /misc_7z/misc.7z.007: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.007 -------------------------------------------------------------------------------- /misc_7z/misc.7z.008: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/misc_7z/misc.7z.008 -------------------------------------------------------------------------------- /reliance/global_vars.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | VERSION = '0.0.0' 4 | VERSION_NO = 0 5 | 6 | default_settings = {'last_file_location': '', 'last_window_geom': '', 'step_save': True, 'interval': 1500, 7 | 'consonant_control': False, 'open_after_output': False, 'pbs': 17, 8 | 'loudness_dir': os.path.join(os.path.expanduser('~'), "Desktop"), 'forced_aligner': 'mfa', 9 | 'last_ver_num': VERSION_NO, 'save_dub_after_output': False, 'enable_dyn_correction': True, 10 | 'output_consonants': False, 'output_format': 'vsqx'} 11 | settings = default_settings 12 | 13 | # .vsqx 14 | dots_per_beat = 480 # settled by vocaloid 15 | tempo = 12000 # beats*100 per min 16 | ms_per_dot = 6000000 / tempo / dots_per_beat 17 | vsqx_initial = 1 # 可能是提前几个小节 18 | beginning_dots = dots_per_beat * vsqx_initial * 4 # by dots 19 | pbs = settings['pbs'] 20 | 21 | def dot_to_ms(dots): 22 | return int(dots * ms_per_dot + 0.5) 23 | 24 | 25 | # .svp 26 | cents_per_pit = 100 27 | tempo_svp = 120 28 | dots_per_beat_svp = int(7056*1e5) 29 | ms_per_dot_svp = 60*1000 / tempo_svp / dots_per_beat_svp 30 | 31 | def dot_to_ms_svp(dots): 32 | return int(dots * ms_per_dot_svp + 0.5) 33 | 34 | 35 | beginning_ms = dot_to_ms(beginning_dots) 36 | 37 | whether_cons = {'a': False, 'ai': False, 'an': False, 'ang': False, 'ao': False, 'ba': True, 'bai': True, 'ban': True, 'bang': True, 'bao': True, 'bei': True, 'ben': True, 'beng': True, 'bi': True, 'bian': True, 'biao': True, 'bie': True, 'bin': True, 'bing': True, 'bo': True, 'bu': True, 'ca': True, 'cai': True, 'can': True, 'cang': True, 'cao': True, 'ce': True, 'cen': True, 'ceng': True, 'cha': True, 'chai': True, 'chan': True, 'chang': True, 'chao': True, 'che': True, 'chen': True, 'cheng': True, 'chi': True, 'chong': True, 'chou': True, 'chu': True, 'chuai': True, 'chuan': True, 'chuang': True, 'chui': True, 'chun': True, 'chuo': True, 'ci': True, 'cong': True, 'cou': True, 'cu': True, 'cuan': True, 'cui': True, 'cun': True, 'cuo': True, 'da': True, 'dai': True, 'dan': True, 'dang': True, 'dao': True, 'de': True, 'dei': True, 'den': True, 'deng': True, 'di': True, 'dia': True, 'dian': True, 'diao': True, 'die': True, 'ding': True, 'diu': True, 'dong': True, 'dou': True, 'du': True, 'duan': True, 'dui': True, 'dun': True, 'duo': True, 'e': False, 'ei': False, 'en': False, 'eng': False, 'er': False, 'fa': True, 'fan': True, 'fang': True, 'fei': True, 'fen': True, 'feng': True, 'fo': True, 'fou': True, 'fu': True, 'ga': True, 'gai': True, 'gan': True, 'gang': True, 'gao': True, 'ge': True, 'gei': True, 'gen': True, 'geng': True, 'gong': True, 'gou': True, 'gu': True, 'gua': True, 'guai': True, 'guan': True, 'guang': True, 'gui': True, 'gun': True, 'guo': True, 'ha': True, 'hai': True, 'han': True, 'hang': True, 'hao': True, 'he': True, 'hei': True, 'hen': True, 'heng': True, 'hong': True, 'hou': True, 'hu': True, 'hua': True, 'huai': True, 'huan': True, 'huang': True, 'hui': True, 'hun': True, 'huo': True, 'ji': True, 'jia': True, 'jian': True, 'jiang': True, 'jiao': True, 'jie': True, 'jin': True, 'jing': True, 'jiong': True, 'jiu': True, 'ju': True, 'juan': True, 'jue': True, 'jun': True, 'ka': True, 'kai': True, 'kan': True, 'kang': True, 'kao': True, 'ke': True, 'kei': True, 'ken': True, 'keng': True, 'kong': True, 'kou': True, 'ku': True, 'kua': True, 'kuai': True, 'kuan': True, 'kuang': True, 'kui': True, 'kun': True, 'kuo': True, 'la': True, 'lai': True, 'lan': True, 'lang': True, 'lao': True, 'le': True, 'lei': True, 'leng': True, 'li': True, 'lia': True, 'lian': True, 'liang': True, 'liao': True, 'lie': True, 'lin': True, 'ling': True, 'liu': True, 'lo': True, 'long': True, 'lou': True, 'lu': True, 'luan': True, 'lue': True, 'lun': True, 'luo': True, 'lv': True, 'lve': True, 'ma': True, 'mai': True, 'man': True, 'mang': True, 'mao': True, 'me': True, 'mei': True, 'men': True, 'meng': True, 'mi': True, 'mian': True, 'miao': True, 'mie': True, 'min': True, 'ming': True, 'miu': True, 'mo': True, 'mou': True, 'mu': True, 'na': True, 'nai': True, 'nan': True, 'nang': True, 'nao': True, 'ne': True, 'nei': True, 'nen': True, 'neng': True, 'ni': True, 'nian': True, 'niang': True, 'niao': True, 'nie': True, 'nin': True, 'ning': True, 'niu': True, 'nong': True, 'nou': True, 'nu': True, 'nuan': True, 'nue': True, 'nuo': True, 'nv': True, 'o': False, 'ou': False, 'pa': True, 'pai': True, 'pan': True, 'pang': True, 'pao': True, 'pei': True, 'pen': True, 'peng': True, 'pi': True, 'pian': True, 'piao': True, 'pie': True, 'pin': True, 'ping': True, 'po': True, 'pou': True, 'pu': True, 'qi': True, 'qia': True, 'qian': True, 'qiang': True, 'qiao': True, 'qie': True, 'qin': True, 'qing': True, 'qiong': True, 'qiu': True, 'qu': True, 'quan': True, 'que': True, 'qun': True, 'r': False, 'ran': True, 'rang': True, 'rao': True, 're': True, 'ren': True, 'reng': True, 'ri': True, 'rong': True, 'rou': True, 'ru': True, 'rua': True, 'ruan': True, 'rui': True, 'run': True, 'ruo': True, 'sa': True, 'sai': True, 'san': True, 'sang': True, 'sao': True, 'se': True, 'sen': True, 'seng': True, 'sha': True, 'shai': True, 'shan': True, 'shang': True, 'shao': True, 'she': True, 'shei': True, 'shen': True, 'sheng': True, 'shi': True, 'shou': True, 'shu': True, 'shua': True, 'shuai': True, 'shuan': True, 'shuang': True, 'shui': True, 'shun': True, 'shuo': True, 'si': True, 'song': True, 'sou': True, 'su': True, 'suan': True, 'sui': True, 'sun': True, 'suo': True, 'ta': True, 'tai': True, 'tan': True, 'tang': True, 'tao': True, 'te': True, 'tei': True, 'teng': True, 'ti': True, 'tian': True, 'tiao': True, 'tie': True, 'ting': True, 'tong': True, 'tou': True, 'tu': True, 'tuan': True, 'tui': True, 'tun': True, 'tuo': True, 'wa': False, 'wai': False, 'wan': False, 'wang': False, 'wei': False, 'wen': False, 'weng': False, 'wo': False, 'wu': False, 'xi': True, 'xia': True, 'xian': True, 'xiang': True, 'xiao': True, 'xie': True, 'xin': True, 'xing': True, 'xiong': True, 'xiu': True, 'xu': True, 'xuan': True, 'xue': True, 'xun': True, 'ya': False, 'yan': False, 'yang': False, 'yao': False, 'ye': False, 'yi': False, 'yin': False, 'ying': False, 'yo': False, 'yong': False, 'you': False, 'yu': False, 'yuan': False, 'yue': False, 'yun': False, 'za': True, 'zai': True, 'zan': True, 'zang': True, 'zao': True, 'ze': True, 'zei': True, 'zen': True, 'zeng': True, 'zha': True, 'zhai': True, 'zhan': True, 'zhang': True, 'zhao': True, 'zhe': True, 'zhei': True, 'zhen': True, 'zheng': True, 'zhi': True, 'zhong': True, 'zhou': True, 'zhu': True, 'zhua': True, 'zhuai': True, 'zhuan': True, 'zhuang': True, 'zhui': True, 'zhun': True, 'zhuo': True, 'zi': True, 'zong': True, 'zou': True, 'zu': True, 'zuan': True, 'zui': True, 'zun': True, 'zuo': True} 38 | 39 | 40 | if __name__ == '__main__': 41 | print(ms_per_dot*120) -------------------------------------------------------------------------------- /reliance/imitation/audioTools.py: -------------------------------------------------------------------------------- 1 | import pyaudio 2 | import wave 3 | import threading as trd 4 | import time 5 | import struct 6 | import numpy as np 7 | # from praatio.audioio import extractSubwav 8 | 9 | 10 | 11 | CHUNK = 1024 12 | FORMAT = pyaudio.paInt16 13 | CHANNELS = 1 14 | RATE = 48000 15 | # RECORD_SECONDS = 2 16 | DEFAULT_OUTPUT_FILENAME = "speech.wav" 17 | 18 | 19 | # 此处代码有参考 20 | class Recorder: 21 | def __init__(self, of=DEFAULT_OUTPUT_FILENAME): 22 | self.rec_flag = False 23 | self.frames = [] 24 | self.output_filename = of 25 | 26 | def _record(self): 27 | p = pyaudio.PyAudio() 28 | t1 = time.time() 29 | stream = p.open(format=FORMAT, 30 | channels=CHANNELS, 31 | rate=RATE, 32 | input=True, 33 | frames_per_buffer=CHUNK) # 耗很多时间 34 | self.rec_flag = True 35 | 36 | t2 = time.time() 37 | print('录音启动准备时长', t2-t1) 38 | 39 | print("开始录音") 40 | 41 | frames = self.frames 42 | 43 | # for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): 44 | # data = stream.read(CHUNK) 45 | # frames.append(data) 46 | while self.rec_flag: 47 | data = stream.read(CHUNK) 48 | frames.append(data) 49 | 50 | print("录音结束") 51 | 52 | stream.stop_stream() 53 | stream.close() 54 | p.terminate() 55 | 56 | 57 | def start(self): 58 | trd.Thread(target=self._record).start() 59 | 60 | def complete(self, ): # 直接丢弃未完成的chunk 61 | wf = wave.open(self.output_filename, 'wb') 62 | wf.setnchannels(CHANNELS) 63 | p = pyaudio.PyAudio() 64 | wf.setsampwidth(p.get_sample_size(FORMAT)) 65 | p.terminate() 66 | wf.setframerate(RATE) 67 | wf.writeframes(b''.join(self.frames)) 68 | wf.close() 69 | self.abort() 70 | 71 | def abort(self): 72 | self.rec_flag = False 73 | self.frames.clear() 74 | if self.frames: 75 | self.abort() 76 | 77 | 78 | # 部分代码参考自https://www.jianshu.com/p/d5f9077668fd 79 | def to_one_channel_file(file_name, dest_name): 80 | with wave.open(file_name, 'rb') as wf: 81 | channel = wf.getnchannels() 82 | nframes = wf.getnframes() 83 | framerate = wf.getframerate() 84 | str_data = wf.readframes(nframes) 85 | sample_width = wf.getsampwidth() 86 | if channel != 2: 87 | if framerate == 16000: 88 | with open(file_name, 'rb') as f: 89 | data = f.read() 90 | with open(dest_name, 'wb') as f: 91 | f.write(data) 92 | else: 93 | # wf_out = wave.open(dest_name, 'wb') 94 | # wf_out.setnchannels(1) 95 | # wf_out.setframerate(16000) 96 | with open(file_name, 'rb') as f: 97 | data = f.read() 98 | with open(dest_name, 'wb') as f: 99 | f.write(data) 100 | else: 101 | # 将波形数据转换成数组 102 | wave_data = np.fromstring(str_data, dtype=np.short) 103 | wave_data.shape = (-1, 2) 104 | wave_data = wave_data.T 105 | mono_wave = (wave_data[0] + wave_data[1]) / 2 106 | wf_mono = wave.open(dest_name, 'wb') 107 | wf_mono.setnchannels(1) 108 | wf_mono.setframerate(framerate) 109 | wf_mono.setsampwidth(sample_width) 110 | timetotal = [0, 0] 111 | 112 | # 耗时长,约花费音频时长的10.5%的时间 113 | for i in mono_wave: 114 | data = struct.pack(' 0 and self.play_flag: 27 | stream.write(data) 28 | data = wf.readframes(chunk) 29 | self.play_flag = False 30 | stream.stop_stream() 31 | stream.close() 32 | p.terminate() 33 | 34 | def start(self): 35 | trd.Thread(target=self._play).start() 36 | self.play_flag = True 37 | 38 | def stop(self): 39 | self.play_flag = False 40 | self.natural_end = False 41 | 42 | def set_speed(self, speed=1.0): 43 | self.speed_rate = speed 44 | with WavReader(self.fileName) as reader: 45 | with WavWriter(self.alteredName, reader.channels, reader.samplerate) as writer: 46 | phasevocoder(reader.channels, speed=self.speed_rate).run(reader, writer) 47 | 48 | 49 | 50 | if __name__ == "__main__": 51 | p = Player() 52 | p.set_speed(0.5) 53 | p.start() 54 | -------------------------------------------------------------------------------- /reliance/imitation/praatDealer.py: -------------------------------------------------------------------------------- 1 | """ 2 | 生成praat脚本并执行:打开编辑窗口 3 | """ 4 | import os 5 | from time import sleep 6 | from praatio import pitch_and_intensity 7 | import wave 8 | from praatio import textgrid 9 | 10 | SCRIPT_PATH = 'temp.praat' # 需要保持在根目录,使得praat的工作目录与主程序一致 11 | 12 | PRAAT_PATH = 'misc\\Praat-win64_vvTalk.exe' 13 | PR_MIN_PITCH = 75 14 | PR_MAX_PITCH = 500 15 | 16 | 17 | def file_name(path, extension=False): 18 | name = '' 19 | if '\\' in path: 20 | name = path.split('\\')[-1] 21 | elif '/' in path: 22 | name = path.split('/')[-1] 23 | if extension: 24 | return name 25 | else: 26 | return name.split('.')[-2] 27 | 28 | 29 | def make_script(wav_path: str, tg_path: str, new_tg: bool, reopen): 30 | wav_name = file_name(wav_path) 31 | tg_name = file_name(tg_path) 32 | if new_tg: 33 | get_tg = """To TextGrid: \"grid\", \"\" 34 | Save as text file: \"{tgPath}\" 35 | Rename: \"{tgName}\"""".format(tgPath=tg_path, tgName=tg_name) 36 | else: 37 | get_tg = 'Read from file: \"{}\"'.format(tg_path) 38 | if reopen: # 之前格式有问题需要重新保存才能转换为praatio能读的格式,现在已经不需要 39 | reopen_txt = """ 40 | selectObject: "TextGrid {tgName}" 41 | Save as text file: "{tgPath}" 42 | selectObject: "TextGrid {tgName}" 43 | Remove 44 | Read from file: "{tgPath}" 45 | """.format(tgName=tg_name, tgPath=tg_path) 46 | else: 47 | reopen_txt = "" 48 | 49 | script = """# 若没有自动进入编辑,点击菜单栏:Run → Run 50 | # 编辑完成后请按下Continue保存并退出 51 | Read from file: "{wavPath}" 52 | {getTg} 53 | {reopen} 54 | selectObject: "Sound {wavName}" 55 | plusObject: "TextGrid {tgName}" 56 | View & Edit 57 | pause 按下Continue保存并退出 58 | selectObject: "TextGrid {tgName}" 59 | Save as text file: "{tgPath}" 60 | runSystem: "taskkill /f /t /im Praat-win64_vvTalk.exe" 61 | """.format(wavPath=wav_path, getTg=get_tg, reopen=reopen_txt, wavName=wav_name, tgName=tg_name, tgPath=tg_path) 62 | with open(SCRIPT_PATH, 'w', encoding='utf-8') as f: 63 | f.write(script) 64 | 65 | 66 | 67 | def start_edit(wav_path: str, tg_path: str, new_tg: bool, reopen: bool): 68 | make_script(wav_path, tg_path, new_tg, reopen) 69 | # os.startfile(PRAAT_PATH) 70 | # sleep(.1) 71 | # os.system('taskkill /FI "WINDOWTITLE eq Praat Picture"') 72 | os.system('start {} {}'.format(PRAAT_PATH, SCRIPT_PATH)) 73 | 74 | 75 | class PraatScript: 76 | def __init__(self, id_name=None): 77 | """ 78 | param id_name: 区分不同子进程下调用的praat, 主进程则为None 79 | """ 80 | self.id_name = id_name 81 | if id_name is not None: 82 | self.TEMP_PATH = f'misc\\temp\\subprocess_{self.id_name}\\praat_temp\\' 83 | else: 84 | self.TEMP_PATH = 'misc\\temp\\praat_temp\\' 85 | self.PRTEMP_PI = self.TEMP_PATH + 'pitch_intensity.txt' 86 | self.PRTEMP_PI_CC = self.TEMP_PATH + 'pitch_intensity.txt' 87 | self.PRTEMP_I = self.TEMP_PATH + 'intensity.txt' 88 | if not os.path.exists(self.TEMP_PATH): 89 | os.makedirs(self.TEMP_PATH) 90 | 91 | def pitch_intensity(self, wav_path, frame_period, min_pitch=PR_MIN_PITCH, max_pitch=PR_MAX_PITCH): 92 | """ 93 | 94 | :param wav_path: relative path 95 | :param frame_period: 96 | :param min_pitch: 97 | :param max_pitch: 98 | :return: 99 | """ 100 | abs_fn = os.getcwd() + '\\' + wav_path 101 | abs_fn_prtemp = os.getcwd() + '\\' + self.PRTEMP_PI 102 | abs_fn_prtemp_cc = os.getcwd() + '\\' + self.PRTEMP_PI_CC 103 | abs_fn_praat = os.getcwd() + '\\' + PRAAT_PATH 104 | frame_period = frame_period / 1000 105 | 106 | # 参数设定:标准range 107 | 108 | pi_list = pitch_and_intensity.extractPI(abs_fn, abs_fn_prtemp, abs_fn_praat, min_pitch, max_pitch, 109 | sampleStep=frame_period, undefinedValue=0) 110 | # pitch_cc_list = pitch_and_intensity.extractPitch(abs_fn, abs_fn_prtemp_cc, abs_fn_praat, min_pitch, max_pitch, 111 | # sampleStep=frame_period, undefinedValue=0) 112 | # 113 | # for idx, pi in enumerate(pi_list): 114 | # if pi[1] == 0: 115 | # pi_list[idx] = (pi_list[idx][0], pitch_cc_list[idx][1], pi_list[idx][2]) 116 | 117 | return pi_list 118 | 119 | def intensity(self, wav_path, frame_period): 120 | """ 121 | 122 | :param wav_path: absolute path 123 | :param frame_period: 124 | :return: 125 | """ 126 | abs_fn = wav_path 127 | abs_fn_prtemp = os.getcwd() + '\\' + self.PRTEMP_I 128 | abs_fn_praat = os.getcwd() + '\\' + PRAAT_PATH 129 | frame_period = frame_period / 1000 130 | i_list = pitch_and_intensity.extractIntensity(abs_fn, abs_fn_prtemp, abs_fn_praat, PR_MIN_PITCH, 131 | sampleStep=frame_period, 132 | undefinedValue=0) 133 | return [list(x) for x in i_list] # [[second, dB]] 134 | 135 | 136 | def create_seg_tg(wav_path, tg_path, texts: list, just_len=None): 137 | """ 138 | var just_len: 不按text分长度,直接按这个数确定这一段有多少个py。用来在生成默认的seg tg时避免py与text没对齐 139 | """ 140 | bias = 4 141 | with wave.open(wav_path, 'rb') as f: 142 | nframe = f.getnframes() 143 | rate = f.getframerate() 144 | wav_length = nframe / float(rate) # second 145 | nums = [] 146 | texts_with_num = [] 147 | if just_len is None: 148 | for tx in texts: 149 | nums.append(len(tx)) 150 | texts_with_num.append(f'{tx}_{len(tx)}_') 151 | else: 152 | text = ''.join(texts) 153 | nums.append(just_len) 154 | texts_with_num.append(f'{text}_{just_len}_') 155 | entry_list = [] 156 | total_num_with_bias = sum(nums) + len(nums) * bias 157 | lengths = [wav_length * ((n + bias)/total_num_with_bias) for n in nums] 158 | last_bound = 0 159 | for i, text in enumerate(texts_with_num): 160 | entry_list.append((last_bound, last_bound+lengths[i], text)) 161 | last_bound += lengths[i] 162 | tg = textgrid.Textgrid() 163 | tier = textgrid.IntervalTier('segment', entry_list) 164 | tg.addTier(tier) 165 | tg.save(tg_path, 'short_textgrid', False) 166 | 167 | 168 | def get_seg_lengths(tg_path): 169 | full = os.path.abspath(tg_path) 170 | tg = textgrid.openTextgrid(full, includeEmptyIntervals=True) 171 | tier = tg.tierDict['segment'] 172 | lengths = [] 173 | for interval in tier.entryList: 174 | lengths.append(int(interval[2].split('_')[-2])) 175 | return lengths 176 | 177 | 178 | if __name__ == '__main__': 179 | il = i_list = pitch_and_intensity.extractIntensity(r'D:\Files\OneDrive\pycharmfiles\TyTalk_Shuttle\resources' 180 | r'\temp_Recording_1.wav', r'd:\tempIntens.txt', r'D:\Files\OneDrive' 181 | r'\pycharmfiles\TyTalk_Shuttle\misc\Praat-win64_TyTalk.exe', 182 | PR_MIN_PITCH, 183 | undefinedValue=0) 184 | 185 | -------------------------------------------------------------------------------- /reliance/imitation/tts.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | import pyttsx3 as pt 5 | 6 | # huawei cloud tts 7 | 8 | from huaweicloud_sis.client.tts_client import TtsCustomizationClient 9 | from huaweicloud_sis.bean.tts_request import TtsCustomRequest 10 | from huaweicloud_sis.bean.sis_config import SisConfig 11 | from huaweicloud_sis.utils.logger_utils import logger, file_handler 12 | import logging.handlers 13 | 14 | # 修改huawei tts所维护的log的位置 15 | logger.removeHandler(file_handler) 16 | file_handler.close() 17 | try: 18 | os.remove('huaweicloud_sis.log') 19 | except: 20 | pass 21 | 22 | """ 23 | http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text= 24 | """ 25 | 26 | 27 | def base_tts(text, location): 28 | engine = pt.init() 29 | engine.save_to_file(text, location) 30 | engine.runAndWait() 31 | 32 | 33 | def huawei_tts(text, location): 34 | # 修改huawei tts所维护的log的位置 35 | adapted_handler = logging.handlers.RotatingFileHandler('misc/tts/huaweicloud_sis.log', maxBytes=1024 * 1024, 36 | backupCount=5, encoding='utf-8') 37 | adapted_handler.setLevel(logging.INFO) 38 | adapted_handler.setFormatter(logging.Formatter('[%(asctime)s] - [%(levelname)s] - [%(message)s]')) 39 | logger.addHandler(adapted_handler) 40 | assert len(text.encode('utf8')) <= 500 41 | paras = get_config() 42 | ak, sk, region, project_id = paras 43 | text = text # 待合成文本,不超过500字 44 | path = location # 保存路径,需要具体到音频文件,如D:/test.wav,可在设置中选择不保存本地 45 | 46 | # step1 初始化客户端 47 | config = SisConfig() 48 | config.set_connect_timeout(10) # 设置连接超时,单位s 49 | config.set_read_timeout(10) # 设置读取超时,单位s 50 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 51 | # config.set_proxy(proxy) 52 | ttsc_client = TtsCustomizationClient(ak, sk, region, project_id, sis_config=config) 53 | 54 | # step2 构造请求 55 | ttsc_request = TtsCustomRequest(text) 56 | # 设置请求,所有参数均可不设置,使用默认参数 57 | # 设置属性字符串, language_speaker_domain, 默认chinese_xiaoyan_common 58 | ttsc_request.set_property('chinese_huaxiaowen_common') 59 | # 设置音频格式,默认wav,可选mp3和pcm 60 | ttsc_request.set_audio_format('wav') 61 | # 设置采样率,8000 or 16000, 默认8000 62 | ttsc_request.set_sample_rate('16000') 63 | # 设置音量,[0, 100],默认50 64 | ttsc_request.set_volume(50) 65 | # 设置音高, [-500, 500], 默认0 66 | ttsc_request.set_pitch(0) 67 | # 设置音速, [-500, 500], 默认0 68 | ttsc_request.set_speed(0) 69 | # 设置是否保存,默认False 70 | ttsc_request.set_saved(True) 71 | # 设置保存路径,只有设置保存,此参数才生效 72 | ttsc_request.set_saved_path(path) 73 | 74 | # step3 发送请求,返回结果。如果设置保存,可在指定路径里查看保存的音频。 75 | try: 76 | result = ttsc_client.get_ttsc_response(ttsc_request) 77 | # print(json.dumps(result, indent=2, ensure_ascii=False)) 78 | finally: 79 | logger.removeHandler(adapted_handler) 80 | adapted_handler.close() 81 | 82 | 83 | def get_config(): 84 | par = [] 85 | with open(r'misc/tts/huawei.txt') as f: 86 | for line in f: 87 | line = line.strip() 88 | if not line or line[0] == '#': 89 | continue 90 | assert line 91 | par.append(line) 92 | return par 93 | 94 | 95 | def render(text, location): 96 | try: 97 | huawei_tts(text, location) 98 | except: 99 | base_tts(text, location) 100 | 101 | if __name__ == '__main__': 102 | base_tts('今天的天气还是挺不错的', r'E:\Files\Projects\TyTalk\test.wav') 103 | -------------------------------------------------------------------------------- /reliance/interface/commandline.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import argparse 3 | import reliance.core 4 | 5 | 6 | def parse_interface(): 7 | args = sys.argv 8 | print(args) 9 | if len(args) > 1 and args[1] == 'cmd': 10 | run_gui = False 11 | else: 12 | print('调用命令行功能必须使用cmd命令,例如:\n>>> tytalk.exe cmd auto -t 我一把把把把住了。') 13 | run_gui = True 14 | 15 | return run_gui 16 | 17 | 18 | class CmdUI: 19 | def __init__(self, core: reliance.core.TalkCore): 20 | self.core = core 21 | self.output_dir = None 22 | 23 | def execute_command(self): 24 | parser = argparse.ArgumentParser('调用命令行功能必须使用cmd命令,例如:\n>>> vvTalk.exe cmd auto -t 我一把把把把住了。\n默认输出在根目录\\outputs文件夹中') 25 | parser.add_argument('ui') 26 | parser.add_argument('operation', help='(必要)操作命令: "auto"或"auto_fast"') 27 | parser.add_argument('-f', '--file', help='朗读文字的文件地址 (utf8编码)') 28 | parser.add_argument('-t', '--text', help='朗读文字(覆盖--file参数)') 29 | parser.add_argument('-fm', '--format', help='指定输出格式: "vsqx"(默认)或"svp"', default='vsqx') 30 | parser.add_argument('-o', '--output', help='指定输出文件地址', default=None) 31 | args = parser.parse_args() 32 | 33 | operation = args.operation 34 | if args.text: 35 | text = args.text 36 | else: 37 | with open(args.file, encoding='utf-8') as f: 38 | text = f.read() 39 | if args.format not in ('vsqx', 'svp'): 40 | parser.error(f'--format参数必须传入"vsqx"或"svp", 而不是"{args.format}"') 41 | else: 42 | self.core.settings.update({'output_format': args.format}) 43 | if operation == 'auto': 44 | self.imi_pipeline(text) 45 | if operation == 'auto_fast': 46 | self.auto_fast(text) 47 | self.output_dir = args.output 48 | 49 | def imi_pipeline(self, text): 50 | self.core.editor.append_item(0, text) 51 | self.core.editor.batch_imitate_pipeline([0], join=True) 52 | self.core.output_tune_file([0], forced_dir=self.output_dir) 53 | 54 | def auto_fast(self, text): 55 | self.core.editor.append_item(0, text) 56 | self.core.editor.fast_auto([0]) 57 | self.core.output_tune_file([0], forced_dir=self.output_dir) 58 | 59 | 60 | -------------------------------------------------------------------------------- /reliance/output/dub.py: -------------------------------------------------------------------------------- 1 | import pysrt as p 2 | from reliance.global_vars import dot_to_ms, beginning_ms 3 | from reliance.tyTalk.talker import Talker 4 | import re 5 | from collections import Counter 6 | 7 | 8 | 9 | sep = '??!!,,。;;::\s' 10 | def split_and_align(text, py): 11 | """ 12 | main中,timing信息本就不包括sil 13 | --> texts and their corresponding index in the py list including sil, end idx included 14 | """ 15 | t = Talker() 16 | py_ref = [re.sub('[01234?]', '', p) for p in py] 17 | py_ref_nosil = [p for p in py_ref if p != 'sil'] 18 | sents = re.split(f'[{sep}]', text) 19 | sents = [sent for sent in sents if sent] 20 | 21 | py_ori = [] 22 | py_ori_nosil = [] 23 | for sent in sents: 24 | py_sent = t.get_py(sent)[0] 25 | py_sent = [re.sub('[012345?]', '', p) for p in py_sent] 26 | py_ori.append(py_sent) 27 | py_ori_nosil.append([p for p in py_sent if p != 'sil']) 28 | py_ori_nosil_len = [len(py) for py in py_ori_nosil] 29 | len_ori = sum(py_ori_nosil_len) 30 | 31 | # py_ref_idx = [tuple(p) for p in enumerate(py_ref)] 32 | py_ref_idx = [tuple(p) for p in enumerate(py_ref_nosil)] 33 | py_ref_idx_nosil = [p for p in py_ref_idx if p[1] != 'sil'] 34 | 35 | if len_ori == len(py_ref_nosil): 36 | # 当长度相等时,默认参考py和文字py是一一对应的关系 37 | items = [] 38 | start_idx = 0 39 | for i, sent in enumerate(sents): 40 | py_len_sent = py_ori_nosil_len[i] 41 | end_idx = start_idx + py_len_sent 42 | items.append((py_ref_idx_nosil[start_idx][0], py_ref_idx_nosil[end_idx-1][0], sent)) 43 | start_idx = end_idx 44 | return items 45 | 46 | 47 | def mismatch_score(ori_left, ori_right, ref, right_start): 48 | c_ori_left = Counter(ori_left) 49 | c_ori_right = Counter(ori_right) 50 | c_ref_left = Counter(ref[:right_start]) 51 | c_ref_right = Counter(ref[right_start:]) 52 | left_diff = sum((c_ori_left - c_ref_left).values())+sum((c_ref_left - c_ori_left).values()) 53 | right_diff = sum((c_ori_right - c_ref_right).values())+sum((c_ref_right - c_ori_right).values()) 54 | return left_diff + right_diff 55 | 56 | # end_idx included 57 | items = [] 58 | start_idx = 0 59 | for i, sent in enumerate(sents): 60 | if i == len(sents)-1: 61 | cur_end_idx = len(py_ref_nosil) 62 | else: 63 | py_sent = py_ori_nosil[i] 64 | py_sent_next = py_ori_nosil[i+1] 65 | cur_end_idx = start_idx + len(py_sent) 66 | last_possible_end_idx = cur_end_idx + len(py_ori_nosil[i+1]) 67 | scores = {} 68 | for n in range(start_idx, last_possible_end_idx+1): 69 | ref = py_ref_nosil[start_idx:last_possible_end_idx+1] 70 | scores[n] = mismatch_score(py_sent, py_sent_next, ref, n-start_idx) 71 | cur_end_idx = min(scores, key=lambda x: scores[x]) 72 | if cur_end_idx == start_idx: 73 | cur_end_idx += 1 74 | items.append((py_ref_idx_nosil[start_idx][0], py_ref_idx_nosil[cur_end_idx-1][0], sent)) 75 | start_idx = cur_end_idx 76 | 77 | return items 78 | 79 | 80 | def py_to_time(items, timing): 81 | data = [] 82 | for item in items: 83 | start_dot = timing[item[0]][0] 84 | start_time = dot_to_ms(start_dot) 85 | end_dot = timing[item[1]][0] + timing[item[1]][1] 86 | end_time = dot_to_ms(end_dot) 87 | text = item[2] 88 | data.append((start_time, end_time, text)) 89 | 90 | return data 91 | 92 | 93 | def to_dub(data, path=None, shift=0): 94 | """ 95 | var data: [(start_time, end_time, text)] 96 | """ 97 | dub = p.srtfile.SubRipFile() 98 | for i, datum in enumerate(data): 99 | dub.append(p.srtitem.SubRipItem(i, datum[0], datum[1], datum[2])) 100 | dub.shift(milliseconds=shift) 101 | if path is not None: 102 | dub.save(path) 103 | else: 104 | return dub 105 | 106 | 107 | def to_srt_file(text, py, timing, path, starttime=0): 108 | items = split_and_align(text, py) 109 | data = py_to_time(items, timing) 110 | to_dub(data, path, starttime) 111 | 112 | 113 | def batch_to_srt_file(data, path, interval, tune_format): 114 | """ 115 | data: [(text, py, timing),] 116 | interval: in milliseconds 117 | tune_format: 'vsqx' or 'svp' 118 | """ 119 | dubs = [] 120 | if tune_format == 'vsqx': 121 | start_time = beginning_ms 122 | elif tune_format == 'svp': 123 | start_time = 0 124 | else: 125 | start_time = 0 126 | for n, datum in enumerate(data): 127 | text, py, timing = datum 128 | items = split_and_align(text, py) 129 | data = py_to_time(items, timing) 130 | dub = to_dub(data, shift=start_time) 131 | start_time = dub[-1].end 132 | start_time = start_time.hours*60*60*1000+\ 133 | start_time.minutes*60*1000+\ 134 | start_time.seconds*1000+\ 135 | start_time.milliseconds+\ 136 | interval 137 | dubs.append(dub) 138 | out_dub = p.srtfile.SubRipFile() 139 | counter = 0 140 | for dub in dubs: 141 | for item in dub: 142 | out_dub.append(p.srtitem.SubRipItem(counter, item.start, item.end, item.text)) 143 | counter+=1 144 | out_dub.save(path) 145 | 146 | 147 | 148 | 149 | # test 150 | if __name__ == '__main__': 151 | r = split_and_align('你好啊,天气可以', 'sil ni2 hai xing bu xing a sil tian sil qi hai ke yi sil'.split(' ')) 152 | print(r) -------------------------------------------------------------------------------- /reliance/sentSeg.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def seg(t: str): 5 | sent_list = [] 6 | text = t 7 | cur_sent = '' 8 | for c in text: 9 | cur_sent = cur_sent + c 10 | if re.match('[。::;;?!?!…\n\r]+', c): 11 | if c in '\n\r': 12 | cur_sent = cur_sent[:-1] 13 | if cur_sent: 14 | sent_list.append(cur_sent) 15 | cur_sent = '' 16 | if cur_sent: 17 | sent_list.append(cur_sent) 18 | return sent_list 19 | -------------------------------------------------------------------------------- /reliance/tyTalk/talkerReliance/arabToChi.py: -------------------------------------------------------------------------------- 1 | """‘两’与‘二’的区分:二用在二十以内时 2 | update 3.12 修正了数字过长无法找到对应数量词的bug 3 | """ 4 | num_str_start_symbol = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9','10', '.'] 5 | # more_num_str_symbol = ['零', '一', '二', '两', '三', '四', '五', '六', '七', '八', '九', '十', '百', '千', '万', '亿'] 6 | num_dict = {'1':'一', '2':'二', '3':'三', '4':'四', '5':'五', '6':'六', '7':'七', '8':'八', '9':'九', '0':'零', '.': '点'} 7 | index_dict = {1:'', 2:'十', 3:'百', 4:'千', 5:'万', 6:'十', 7:'百', 8:'千', 9:'亿'} 8 | import re 9 | def to_Chiness_num(num): 10 | 11 | nums = list(num) 12 | digits = [] 13 | if '.' in nums: 14 | i = nums.index('.') 15 | digits = nums[i:] 16 | digits = [num_dict[d] for d in digits] 17 | nums = nums[:i] 18 | 19 | if len(nums) > 9: # 太长不转换 20 | digits = [num_dict[d] for d in nums] + digits 21 | nums = [] 22 | 23 | nums_index = [x for x in range(1, len(nums)+1)][-1::-1] 24 | 25 | string = '' 26 | for index, item in enumerate(nums): 27 | string = "".join((string, num_dict[item], index_dict[nums_index[index]])) 28 | 29 | string = re.sub("零[十百千零]*", "零", string) 30 | string = re.sub("零万", "万", string) 31 | string = re.sub("亿万", "亿零", string) 32 | string = re.sub("零零", "零", string) 33 | string = re.sub("零\\b", "", string) 34 | string = re.sub('二千', '两千', string) 35 | string = re.sub('二万', '两万', string) 36 | string = re.sub('二亿', '两亿', string) 37 | 38 | string = string + "".join(digits) 39 | 40 | if string[:2] == '一十': 41 | string = string[1:] 42 | return string 43 | 44 | def changeArabNumToChinese(oriStr, simple=False): 45 | if simple: 46 | output_list = [] 47 | for ch in oriStr: 48 | new_ch = num_dict.get(ch, ch) 49 | output_list.append(new_ch) 50 | return ''.join(output_list) 51 | 52 | lenStr = len(oriStr) 53 | aProStr = '' 54 | if lenStr == 0: 55 | return aProStr 56 | 57 | hasNumStart = False #默认 不含阿拉伯数字 58 | numberStr = '' #默认 不含阿拉伯数字 59 | endWithDot = False 60 | for idx in range(lenStr): #遍历所有 字符 61 | if oriStr[idx] in num_str_start_symbol: #当前字符 是 阿拉伯数字或"." 62 | if not hasNumStart: 63 | hasNumStart = True 64 | endWithDot = oriStr[idx] == '.' 65 | 66 | numberStr += oriStr[idx] #将个位阿拉伯数字 累加到输出字符串 67 | 68 | 69 | else: #当前字符 不是 阿拉伯数字或"." 70 | if hasNumStart: #当前字符不是数字,但是【之前的字符 包含数字】,先把之前的数字进行转换,并累加 71 | if endWithDot: # 最后以.结尾则忽略这个. 72 | numberStr = numberStr[:-1] 73 | 74 | numResult = str(to_Chiness_num(numberStr)) # 将之前的阿拉伯数字 转换为 汉字数字 75 | 76 | aProStr += numResult #将汉字数字,累加到 输出字符串 77 | 78 | numberStr = '' # 数字清空,为了记录下一次的 阿拉伯数字 79 | hasNumStart = False # 设置为false 恢复到初始值 80 | 81 | aProStr += oriStr[idx] #将不是阿拉伯的 当前汉字字符 累加到 输出字符串 82 | 83 | 84 | if len(numberStr) > 0: # 处理以数字 结尾的情况 ,不能去掉。 '12套餐12' 85 | resultNum = to_Chiness_num(numberStr) # 将汉字数字 转换为 阿拉伯数字 86 | aProStr += str(resultNum) 87 | 88 | return aProStr 89 | 90 | def convert(str, simple=False): 91 | return changeArabNumToChinese(str, simple) 92 | 93 | 94 | """ 95 | 版权声明:本文件内的代码的基础是CSDN博主「HeartBeating_RUC」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 96 | 原文链接:https://blog.csdn.net/weixin_40467413/article/details/86015439 97 | """ -------------------------------------------------------------------------------- /reliance/tyTalk/talkerReliance/baiduCleint.py: -------------------------------------------------------------------------------- 1 | from aip import AipNlp 2 | c = AipNlp('', '', '') 3 | 4 | 5 | def client(): 6 | return c 7 | -------------------------------------------------------------------------------- /reliance/tyTalk/talkerReliance/pyCorrect.py: -------------------------------------------------------------------------------- 1 | # 手工指定额外的拼音规则,目前是两次循环嵌套,算法可以优化.不改变的项留空 2 | # 只能指定儿化,不能取消。儿化必须是后面接'儿',当然词长必须大于1 3 | inf = [('姑娘', [(1, 'niang', None)]), ('知了', [(1, 'liao', None)]), ('太阳', [(1, 'yang', None)]), 4 | ('月亮', [(1, 'liang', None)]), ('故事', [(1, 'shi', None)]), ('少爷', [(1, 'ye', None)]), 5 | ('玩儿', [(0, '', True)]), ('鹿尾儿', [(1, 'yi3', None)]), 6 | ('海蜇', [(1, 'zhe2', None)]), ('东西', [(1, 'xi', None)]), ('衣服', [(1, 'fu', None)]), 7 | ('肚子', [(0, 'du4', None)]), ('消息', [(1, 'xi', None)]), ('技术', [(1, 'shu', None)]), 8 | ('看见', [(1, 'jian', None)]), ('谢谢', [(1, 'xie', None)]), ('回来', [(1, 'lai', None)]), 9 | ('长达', [(0, 'chang2', None)]), ('明白', [(1, 'bai', None)]), ('命令行', [(2, 'hang2', None)]), 10 | ('收拾', [(1, 'shi', None)]), ('曲师', [(0, 'qu3', None)]), ('乐正', [(0, 'yue4', None)]), 11 | ('调教', [(0, 'tiao2', None)]), ('谁', [(0, 'shei2', None)]) 12 | ] 13 | -------------------------------------------------------------------------------- /reliance/tyTalk/talkerReliance/semanticEncoder.py: -------------------------------------------------------------------------------- 1 | """ 2 | 依据句法结构推测语义展开的过程,以评价各个音节的正式度并划分基础节奏(未在最后一层受音节数量影响时)。 3 | """ 4 | from aip import AipNlp 5 | import pickle 6 | import pydotplus 7 | import os 8 | from PIL import Image 9 | import math 10 | os.environ["PATH"] += os.pathsep + r'D:\Program Files\Graphviz\bin' 11 | cx_dic = {'Ag': '形语素', 'a': '形容词', 'ad': '副形词', 'an': '名形词', 'b': '区别词', 'c': '连词', 'dg': '副语素', 'd': '副词', 'e': '叹词', 'f': '方位词', 'g': '语素', 'h': '前接成分', 'i': '成语', 'j': '简称略语', 'k': '后接成分', 'l': '习用语', 'm': '数词', 'Ng': '名语素', 'n': '名词', 'nr': '人名', 'ns': '地名', 'nt': '机构团体', 'nz': '其他专名', 'o': '拟声词', 'p': '介词', 'q': '量词', 'r': '代词', 's': '处所词', 'tg': '时语素', 't': '时间词', 'u': '助词', 'vg': '动语素', 'v': '动词', 'vd': '副动词', 'vn': '名动词', 'w': '标点符号', 'x': '非语素字', 'y': '语气词', 'z': '状态词', 'un': '未知词'} 12 | yc_dic = {'ATT': '定中关系', 'QUN': '数量关系(quantity)', 'COO': '并列关系(coordinate)', 'APP': '同位关系(appositive)', 'ADJ': '附加关系(adjunct)', 'VOB': '动宾关系(verb-object)', 'POB': '介宾关系(preposition-object)', 'SBV': '主谓关系(subject-verb)', 'SIM': '比拟关系(similarity)', 'TMP': '时间关系(temporal)', 'LOC': '处所关系(locative)', 'DE': '“的”字结构', 'DI': '“地”字结构', 'DEI': '“得”字结构', 'SUO': '“所”字结构', 'BA': '“把”字结构', 'BEI': '“被”字结构', 'ADV': '状中结构(adverbial)', 'CMP': '动补结构(complement)', 'DBL': '兼语结构(double)', 'CNJ': '关联词(conjunction)', 'CS': '关联结构(conjunctive structure)', 'MT': '语态结构(mood-tense)', 'VV': '连谓结构(verb-verb)', 'HED': '核心(head)', 'FOB': '前置宾语(fronting object)', 'DOB': '双宾语(double object)', 'TOP': '主题(topic)', 'IS': '独立结构(independent structure)', 'IC': '独立分句(independent clause)', 'DC': '依存分句(dependent clause)', 'VNV ': '叠词关系(verb-no-verb or verb-one-verb)', 'YGC': '一个词', 'WP': '标点'} 13 | 14 | text = '噜嗦地讲着埃及话' 15 | client = AipNlp('18561004', 'pYNIu5ocRxj82BkaI5CZzR8I', 'AehSQG7Uji17o0vWBqWPVj5lBqMMrRNn') 16 | result = client.depParser(text) 17 | with open('result.pkl', 'wb') as f: 18 | pickle.dump(result, f) 19 | 20 | # with open('result.pkl', 'rb') as f: 21 | # result = pickle.load_from(f) 22 | 23 | items = result['items'] 24 | items_d = {item['id']: item for item in items} 25 | continuing = True 26 | # flow_rely = {id_: 1 for id_ in items_d} 27 | # stack_rely = {id_: 0 for id_ in items_d} 28 | # while continuing: 29 | # continuing = False 30 | # for id_ in items_d: 31 | # if flow_rely[id_]: 32 | # try: 33 | # flow_rely[items_d[id_]['head']] += flow_rely[id_] 34 | # except KeyError: # 根依赖 35 | # pass 36 | # stack_rely[id_] += flow_rely[id_] 37 | # flow_rely[id_] = 0 38 | # continuing = True 39 | 40 | children = {id_: [] for id_ in items_d} 41 | for id_ in items_d: 42 | try: 43 | children[items_d[id_]['head']].append(id_) 44 | except KeyError: # 根词 45 | pass 46 | utterred = {id_: False for id_ in items_d} 47 | disconnected = {id_: False for id_ in items_d} 48 | 49 | 50 | def get_children_num(id_, out=None): 51 | """ 52 | :return: [expressed_num, inexpressed_num] 53 | """ 54 | if not out: 55 | out = [0, 0] 56 | if utterred[id_] and not disconnected[id_]: 57 | out[0] += 1 58 | else: 59 | out[1] += 1 60 | rely_ids = children[id_] 61 | for rely_id in rely_ids: 62 | get_children_num(rely_id, out) 63 | return out 64 | 65 | def get_distance(ia, ib, default=2): 66 | """ 67 | 求a到b的距离(b-a,距离逆箭头方向增加,即箭头方向为距离的负方向) 68 | :return 带正负号的距离,若不在同一树,则返回默认距离 69 | """ 70 | 71 | def get_children(id, out=None, cnt=0): 72 | if not out: 73 | out = [] 74 | cnt += 1 75 | direct = children[id] 76 | for child in direct: 77 | out.append((child, cnt)) 78 | get_children(child, out, cnt) 79 | return out 80 | def get_masters(id, out=None, cnt=0): 81 | if id == 0: 82 | return out 83 | if not out: 84 | out = [] 85 | cnt += 1 86 | direct = items_d[id]['head'] 87 | out.append((direct, cnt)) 88 | get_masters(direct, out, cnt) 89 | return out 90 | dist = 0 91 | ia_inf = dict(get_children(ia)) 92 | ib_inf = dict(get_children(ib)) 93 | if ia in ib_inf: 94 | dist = -ib_inf[ia] 95 | elif ib in ia_inf: 96 | dist = ia_inf[ib] 97 | else: # 并行修饰情况 98 | m_ia_inf = get_masters(ia) # 用list保持顺序 99 | m_ia_list = [inf[0] for inf in m_ia_inf] 100 | m_ib_inf = get_masters(ib) 101 | m_ib_inf_d = dict(m_ib_inf) 102 | for mst_b in m_ib_inf: 103 | if mst_b[0] in m_ia_list: 104 | dist = - m_ib_inf_d[mst_b[0]] 105 | break 106 | # print(items_d[ia], dist) 107 | return dist 108 | # 按照语序,渲染,以依赖链接为单位 109 | 110 | def get_discontinuity(fa, fb, fl, i): 111 | def sigmoid(x, ex=1): 112 | return 1 / (1 + math.exp(-x*ex)) 113 | 114 | ib = i + 1 115 | 116 | if items_d[ib]['deprel'] in ('DE', 'DI', 'DEI'): 117 | fa = 1 118 | 119 | if fl > 0: 120 | fl = fl / 2 121 | else: 122 | fl = - fl 123 | # print(items_d[i]['word'], fl, fb, math.log(sigmoid((-1 / fl) + 0.5*math.log(fb), 2))) 124 | return sigmoid(1.5 * (3 * math.log(fa, 20) + 0.4 * math.log(sigmoid((-1 / fl) + 0.5 * math.log(fb), 2)))) 125 | discontinuity = {} 126 | relation_inf = {} # {id:(A_inf, B_inf, distance)} 127 | for id_ in list(items_d)[:-1]: 128 | utterred[id_] = True 129 | relation_inf.update({id_: (get_children_num(id_)[0], get_children_num(id_ + 1)[1], get_distance(id_, id_+1))}) 130 | inf = relation_inf[id_] 131 | dis = round(get_discontinuity(inf[0], inf[1], inf[2], id_), 2) 132 | discontinuity.update({id_: dis}) 133 | if dis > 0.7: 134 | for i in range(1, id_+1): 135 | disconnected[i] = True 136 | for x, y in relation_inf.items(): 137 | print(items_d[x]['word']) 138 | print(y, ' - ', discontinuity[x]) 139 | print(sum(discontinuity.values())/len(discontinuity)) 140 | 141 | 142 | # for id in relation_inf: 143 | # inf = relation_inf[id] 144 | # print(items_d[id]['word']) 145 | # print(inf, ' - ', round(get_discontinuity(inf[0], inf[1], inf[2]), 2)) 146 | # inf = relation_inf[4] 147 | # print(inf, ' - ', round(get_discontinuity(inf[0], inf[1], inf[2]), 2)) 148 | 149 | 150 | 151 | 152 | for item in result['items']: 153 | item['deprel'] = item['deprel'] + '|' + yc_dic[item['deprel']] 154 | 155 | def make_point(cln): 156 | dot = [] 157 | for item in cln['items']: 158 | id_ = item['id'] 159 | head = item['head'] 160 | deprel = item['deprel'] 161 | dot.append('{} -> {} [label="{}"]'.format(id_, head, deprel)) 162 | dot.append('{}[label="{}"]'.format(id_, item['word'])) 163 | text = """digraph graphname { 164 | subgraph clusterA { 165 | rankdir=TB 166 | node [shape=plaintext,style=filled, fontname="Microsoft YaHei"] 167 | edge [fontname="Microsoft YaHei"] 168 | %s 169 | } 170 | } 171 | """ % '\n'.join(dot) 172 | print(text) 173 | return text 174 | 175 | 176 | graph = pydotplus.graph_from_dot_data(make_point(result)) 177 | with open('pic.png', 'wb') as f: 178 | f.write(graph.create_png()) 179 | pic2 = Image.open('pic.png') 180 | pic2.show() 181 | 182 | """ 183 | import matplotlib.pyplot as plt 184 | graph = pydotplus.graph_from_dot_data(dot) 185 | with open('pic.png', 'wb') as f: 186 | f.write(graph.create_png()) 187 | 188 | im = plt.imread('pic.png') 189 | plt.imshow(im) 190 | plt.show() 191 | """ -------------------------------------------------------------------------------- /reliance/tyTalk/talkerReliance/vocalDict.py: -------------------------------------------------------------------------------- 1 | def diction(): 2 | return {'a': 'a', 'ai': 'aI', 'an': 'a_n', 'ang': 'AN', 'ao': 'AU', 'shi': 's` i`', 'liu': 'l i@U', 'ge': 'k 7', 'ba': 'p a', 'bai': 'p aI', 'ban': 'p a_n', 'bang': 'p AN', 'bao': 'p AU', 'bei': 'p ei', 'ben': 'p @_n', 'beng': 'p @N', 'bi': 'p i', 'bian': 'p iE_n', 'biao': 'p iAU', 'bie': 'p iE_r', 'bin': 'p i_n', 'bing': 'p iN', 'po': 'p_h o', 'bo': 'p o', 'bu': 'p u', 'san': 's a_n', 'si': 's i\\', 'ca': 'ts_h a', 'cai': 'ts_h aI', 'can': 'ts_h a_n', 'cang': 'ts_h AN', 'cao': 'ts_h AU', 'ce': 'ts_h 7', 'cen': 'ts_h @_n', 'ceng': 'ts_h @N', 'cha': 'ts`_h a', 'chai': 'ts`_h aI', 'chan': 'ts`_h a_n', 'chang': 'ts`_h AN', 'zhang': 'ts` AN', 'chao': 'ts`_h AU', 'che': 'ts`_h 7', 'chen': 'ts`_h @_n', 'cheng': 'ts`_h @N', 'chi': 'ts`_h i`', 'chong': 'ts`_h UN', 'chou': 'ts`_h @U', 'chu': 'ts`_h u', 'chuai': 'ts`_h uaI', 'chuan': 'ts`_h ua_n', 'chuang': 'ts`_h uAN', 'chui': 'ts`_h uei', 'chun': 'ts`_h u@_n', 'chuo': 'ts`_h uo', 'ci': 'ts_h i\\', 'cong': 'ts_h UN', 'cou': 'ts_h @U', 'cu': 'ts_h u', 'cuan': 'ts_h ua_n', 'cui': 'ts_h uei', 'cun': 'ts_h u@_n', 'cuo': 'ts_h uo', 'er': '@`', 'da': 't a', 'dai': 't aI', 'dan': 't a_n', 'dang': 't AN', 'dao': 't AU', 'de': 't 7', 'deng': 't @N', 'di': 't i', 'dian': 't iE_n', 'diao': 't iAU', 'die': 't iE_r', 'ding': 't iN', 'diu': 't i@U', 'dong': 't UN', 'dou': 't @U', 'du': 't u', 'duan': 't ua_n', 'dui': 't uei', 'dun': 't u@_n', 'duo': 't uo', 'e': '7', 'en': '@_n', 'jiu': 'ts\\ i@U', 'fa': 'f a', 'fan': 'f a_n','fang': 'f AN', 'fei': 'f ei', 'fen': 'f @_n', 'feng': 'f @N', 'fu': 'f u', 'fou': 'f @U', 'ga': 'k a', 'gai': 'k aI', 'gan': 'k a_n', 'gang': 'k AN', 'gao': 'k AU', 'gei': 'k ei', 'gen': 'k @_n', 'geng': 'k @N', 'gong': 'k UN', 'gou': 'k @U', 'gu': 'k u', 'gua': 'k ua', 'guai': 'k uaI', 'guan': 'k ua_n', 'guang': 'k uAN', 'gui': 'k uei', 'gun': 'k u@_n', 'guo': 'k uo', 'ha': 'x a', 'hai': 'x aI', 'han': 'x a_n', 'xing': 's\\ iN', 'hang': 'x AN', 'hao': 'x AU', 'he': 'x 7', 'hei': 'x ei', 'hen': 'x @_n', 'heng': 'x @N', 'hong': 'x UN', 'hou': 'x @U', 'hu': 'x u', 'hua': 'x ua', 'huai': 'x uaI', 'huan': 'x ua_n', 'huang': 'x uAN', 'hui': 'x uei', 'hun': 'x u@_n', 'huo': 'x uo', 'ji': 'ts\\ i', 'jia': 'ts\\ ia', 'jian': 'ts\\ iE_n', 'jiang': 'ts\\ iAN', 'jiao': 'ts\\ iAU', 'jie': 'ts\\ iE_r', 'jin': 'ts\\ i_n', 'jing': 'ts\\ iN', 'qing': 'ts\\_h iN', 'jiong': 'ts\\ iUN', 'ju': 'ts\\ y', 'juan': 'ts\\ y{_n', 'jue': 'ts\\ yE_r', 'jun': 'ts\\ y_n', 'ka': 'k_h a', 'kai': 'k_h aI', 'kan': 'k_h a_n', 'kang': 'k_h AN', 'kao': 'k_h AU', 'ke': 'k_h 7', 'ken': 'k_h @_n', 'keng': 'k_h @N', 'kong': 'k_h UN', 'kou': 'k_h @U', 'ku': 'k_h u', 'kua': 'k_h ua', 'kuai': 'k_h uaI', 'kuan': 'k_h ua_n', 'kuang': 'k_h uAN', 'kui': 'k_h uei', 'kun': 'k_h u@_n', 'kuo': 'k_h uo', 'wu': 'u', 'la': 'l a', 'lai': 'l aI', 'lan': 'l a_n', 'lang': 'l AN', 'lao': 'l AU', 'le': 'l 7', 'lei': 'l ei', 'leng': 'l @N', 'li': 'l i', 'lia': 'l ia', 'lian': 'l iE_n', 'liang': 'l iAN', 'liao': 'l iAU', 'lie': 'l iE_r', 'lin': 'l i_n', 'ling': 'l iN', 'long': 'l UN', 'lou': 'l @U', 'lu': 'l u', 'lv': 'l y', 'luan': 'l ua_n', 'lve': 'l yE_r', 'lun': 'l u@_n', 'luo': 'l uo', 'ma': 'm a', 'mai': 'm aI', 'man': 'm a_n', 'mang': 'm AN', 'mao': 'm AU', 'me': 'm 7', 'mei': 'm ei', 'men': 'm @_n', 'meng': 'm @N', 'mi': 'm i', 'mian': 'm iE_n', 'miao': 'm iAU', 'mie': 'm iE_r', 'min': 'm i_n', 'ming': 'm iN', 'mo': 'm o', 'mou': 'm @U', 'mu': 'm u', 'na': 'n a', 'nai': 'n aI', 'nan': 'n a_n', 'nang': 'n AN', 'nao': 'n AU', 'nei': 'n ei', 'nen': 'n @_n', 'neng': 'n @N', 'ni': 'n i', 'nian': 'n iE_n', 'niang': 'n iAN', 'niao': 'n iAU', 'nie': 'n iE_r', 'nin': 'n i_n', 'ning': 'n iN', 'niu': 'n i@U', 'nong': 'n UN', 'nu': 'n u', 'nv': 'n y', 'nuan': 'n ua_n', 'nve': 'n yE_r', 'nuo': 'n uo', 'yi': 'i', 'ou': '@U', 'qi': 'ts\\_h i', 'pa': 'p_h a', 'pai': 'p_h aI', 'pan': 'p_h a_n', 'pang': 'p_h AN', 'pao':'p_h AU', 'pei': 'p_h ei', 'pen': 'p_h @_n', 'peng': 'p_h @N', 'pi': 'p_h i', 'pian': 'p_h iE_n', 'piao': 'p_h iAU', 'pie': 'p_h iE_r', 'pin': 'p_h i_n', 'ping': 'p_h iN', 'pou': 'p_h @U', 'pu': 'p_h u', 'qia': 'ts\\_h ia', 'qian': 'ts\\_h iE_n', 'qiang': 'ts\\_h iAN', 'qiao': 'ts\\_h iAU', 'qin': 'ts\\_h i_n', 'qiong': 'ts\\_h iUN', 'qiu': 'ts\\_h i@U', 'qu': 'ts\\_h y', 'quan': 'ts\\_h y{_n', 'que': 'ts\\_h yE_r', 'qun': 'ts\\_h y_n', 'ran': 'z` a_n', 'rang': 'z` AN', 'rao': 'z` AU', 're': 'z` 7', 'ren': 'z` @_n', 'reng': 'z` @N', 'ri': 'z` i`', 'rong': 'z` UN', 'rou': 'z` @U', 'ru': 'z` u', 'ruan': 'z` ua_n', 'rui': 'z` uei', 'run': 'z` u@_n', 'ruo': 'z` uo', 'sa': 's a', 'sai': 's aI', 'sang': 's AN', 'sao': 's AU', 'se':'s 7', 'sen': 's @_n', 'seng': 's @N', 'sha': 's` a', 'shai': 's` aI', 'shan': 's` a_n', 'shang': 's` AN', 'shao': 's` AU', 'she': 's` 7', 'shen': 's` @_n', 'sheng': 's` @N', 'shou': 's` @U', 'shu': 's` u', 'shua': 's` ua', 'shuai': 's` uaI', 'shuan': 's` ua_n', 'shuang': 's` uAN', 'shui': 's` uei', 'shun': 's` u@_n', 'shuo': 's` uo', 'song': 's UN', 'sou': 's @U','su': 's u', 'suan': 's ua_n', 'sui': 's uei', 'sun': 's u@_n', 'suo': 's uo', 'ta': 't_h a', 'tai': 't_h aI', 'tan': 't_h a_n', 'tang': 't_h AN', 'tao': 't_h AU', 'te': 't_h 7', 'teng': 't_h @N', 'ti': 't_h i', 'tian': 't_h iE_n', 'tiao': 't_h iAU', 'tie': 't_h iE_r', 'ting': 't_h iN', 'tong': 't_h UN', 'tou': 't_h @U', 'tu': 't_h u', 'tuan': 't_h ua_n', 'tui': 't_h uei', 'tun': 't_h u@_n', 'wa': 'ua', 'wai': 'uaI', 'wan': 'ua_n', 'wang': 'uAN', 'wei': 'uei', 'wen': 'u@_n', 'weng': 'u@N', 'wo': 'uo', 'xi': 's\\ i', 'xia': 's\\ ia', 'xian': 's\\ iE_n', 'xiang': 's\\ iAN', 'xiao': 's\\ iAU', 'xie': 's\\ iE_r', 'xin': 's\\ i_n', 'xiong': 's\\ iUN', 'xiu': 's\\ i@U', 'xu': 's\\ y', 'xuan': 's\\ y{_n', 'xue': 's\\ yE_r', 'xun': 's\\ y_n', 'ya': 'ia', 'yan': 'iE_n', 'yang': 'iAN', 'yao': 'iAU', 'ye': 'iE_r', 'yin': 'i_n', 'ying': 'iN', 'you': 'i@U', 'yong': 'iUN', 'yu': 'y', 'yuan': 'y{_n', 'yue': 'yE_r', 'yun': 'y_n', 'za': 'ts a', 'zai': 'ts aI', 'zan': 'ts a_n', 'zang': 'ts AN', 'zao': 'ts AU', 'ze': 'ts 7', 'zei': 'ts ei', 'zen': 'ts @_n', 'zeng': 'ts @N', 'zha': 'ts` a', 'zhai': 'ts` aI', 'zhan': 'ts` a_n', 'zhao': 'ts` AU', 'zhe': 'ts` 7', 'zhen': 'ts` @_n', 'zheng': 'ts` @N', 'zhi': 'ts` i`', 'zhong': 'ts` UN', 'zhou': 'ts` @U', 'zhu': 'ts` u', 'zhua': 'ts` ua', 'zhuai': 'ts` uaI', 'zhuan': 'ts` ua_n', 'zhuang': 'ts` uAN', 'zhui': 'ts` uei', 'zhun': 'ts` u@_n', 'zhuo': 'ts` uo', 'zi': 'ts i\\', 'zong': 'ts UN', 'zou': 'ts @U', 'zu': 'ts u', 'zuan': 'ts ua_n', 'zui': 'ts uei', 'zun': 'ts u@_n', 'zuo': 'ts uo', 'shei': 's` ei', 'chua': 'ts`_h ua', 'dei': 't ei', 'den': 't @_n', 'ne': 'n 7', 'dia': 't ia', 'fo': 'f o', 'lo': 'l o', 'miu': 'm i@U', 'nou': 'n @U', 'o': 'o', 'qie': 'ts\\_h iE_r', 'tuo': 't_h uo', 'zhei': 'ts` ei', 'ei': 'ei'} 3 | if __name__ == '__main__': 4 | d = diction() 5 | with open('diction.txt', 'w', encoding='utf-8') as f: 6 | for k in d: 7 | f.write(k+','+d[k]+'\n') -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pip 2 | lxml 3 | tqdm 4 | requests 5 | colorama 6 | PyYAML 7 | numba 8 | numpy 9 | llvmlite 10 | cffi 11 | scipy 12 | setuptools 13 | Cython 14 | pooch 15 | packaging 16 | appdirs 17 | matplotlib 18 | joblib 19 | certifi 20 | chardet 21 | SoundFile 22 | audioread 23 | resampy 24 | decorator 25 | scikit-learn 26 | praatio 27 | six 28 | threadpoolctl 29 | Pillow 30 | urllib3 31 | idna 32 | pyparsing 33 | pycparser 34 | pysrt 35 | pyttsx3 36 | audiotsm2 37 | jieba 38 | pypinyin 39 | pyworld 40 | pydub 41 | pypiwin32 42 | pypinyin-dict -------------------------------------------------------------------------------- /setup.bat: -------------------------------------------------------------------------------- 1 | CALL conda install -c conda-forge montreal-forced-aligner -y 2 | pip install -r requirements.txt 3 | pip install setup_install\PyAudio-0.2.11-cp38-cp38-win_amd64.whl 4 | cd setup_install/huaweicloud-python-sdk-sis-1.7.1 5 | python setup.py install 6 | cd .. 7 | cd .. -------------------------------------------------------------------------------- /setup_install/PyAudio-0.2.11-cp38-cp38-win_amd64.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/PyAudio-0.2.11-cp38-cp38-win_amd64.whl -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/auth/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/auth/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/auth/aksk_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import json 4 | from huaweicloud_sis.auth import signer 5 | from huaweicloud_sis.bean.sis_config import SisConfig 6 | from huaweicloud_sis.utils import http_utils 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.utils.logger_utils import logger 9 | 10 | 11 | def get_signed_headers(ak, sk, url, headers, params, http_method): 12 | """ 13 | 根据ak和sk以及请求信息获取加密头部 14 | @:return 加密的头部 15 | """ 16 | sig = signer.Signer() 17 | sig.Key = ak 18 | sig.Secret = sk 19 | if params is None: 20 | body = '' 21 | else: 22 | body = params 23 | if isinstance(params, dict): 24 | body = json.dumps(params) 25 | r = signer.HttpRequest(http_method, url, headers, body) 26 | sig.Sign(r) 27 | return r.headers 28 | 29 | 30 | def aksk_connect(ak, sk, url, headers, params, http_method, config=None): 31 | """ 32 | 根据url,返回json 33 | :param ak: ak 34 | :param sk: sk 35 | :param url: 完整请求url 36 | :param headers: 请求header,dict 37 | :param params: 请求参数, dict 38 | :param http_method: 请求方法,'POST' or 'GET', 其他会报错 39 | :param config: SisConfig(), 配置超时和代理 40 | :return: http返回结果转化为json 41 | """ 42 | sis_config = config 43 | if sis_config is None: 44 | sis_config = SisConfig() 45 | if not isinstance(sis_config, SisConfig): 46 | error_msg = 'the param \'config\' in aksk_connect must be SisConfig class' 47 | logger.error(error_msg) 48 | raise ClientException(error_msg) 49 | signed_headers = get_signed_headers(ak, sk, url, headers, params, http_method) 50 | time_out = (sis_config.get_connect_timeout(), sis_config.get_read_timeout()) 51 | resp = http_utils.http_connect(url, signed_headers, params, http_method, time_out, sis_config.get_proxy(), 52 | sis_config.get_certificate_check()) 53 | json_result = http_utils.parse_resp(resp) 54 | if resp is not None: 55 | resp.close() 56 | return json_result 57 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/auth/signer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import copy 4 | import sys 5 | import hashlib 6 | import hmac 7 | import binascii 8 | from datetime import datetime 9 | 10 | if sys.version_info.major < 3: 11 | from urllib import quote, unquote 12 | 13 | 14 | def hmacsha256(keyByte, message): 15 | return hmac.new(keyByte, message, digestmod=hashlib.sha256).digest() 16 | 17 | 18 | # Create a "String to Sign". 19 | def StringToSign(canonicalRequest, t): 20 | bytes = HexEncodeSHA256Hash(canonicalRequest) 21 | return "%s\n%s\n%s" % (Algorithm, datetime.strftime(t, BasicDateFormat), bytes) 22 | 23 | else: 24 | from urllib.parse import quote, unquote 25 | 26 | 27 | def hmacsha256(keyByte, message): 28 | return hmac.new(keyByte.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).digest() 29 | 30 | 31 | # Create a "String to Sign". 32 | def StringToSign(canonicalRequest, t): 33 | bytes = HexEncodeSHA256Hash(canonicalRequest.encode('utf-8')) 34 | return "%s\n%s\n%s" % (Algorithm, datetime.strftime(t, BasicDateFormat), bytes) 35 | 36 | 37 | def urlencode(s): 38 | return quote(s, safe='~') 39 | 40 | 41 | def findHeader(r, header): 42 | for k in r.headers: 43 | if k.lower() == header.lower(): 44 | return r.headers[k] 45 | return None 46 | 47 | 48 | # HexEncodeSHA256Hash returns hexcode of sha256 49 | def HexEncodeSHA256Hash(data): 50 | sha256 = hashlib.sha256() 51 | sha256.update(data) 52 | return sha256.hexdigest() 53 | 54 | 55 | # HWS API Gateway Signature 56 | class HttpRequest: 57 | def __init__(self, method="", url="", headers=None, body=""): 58 | self.method = method 59 | spl = url.split("://", 1) 60 | scheme = 'http' 61 | if len(spl) > 1: 62 | scheme = spl[0] 63 | url = spl[1] 64 | query = {} 65 | spl = url.split('?', 1) 66 | url = spl[0] 67 | if len(spl) > 1: 68 | for kv in spl[1].split("&"): 69 | spl = kv.split("=", 1) 70 | key = spl[0] 71 | value = "" 72 | if len(spl) > 1: 73 | value = spl[1] 74 | if key != '': 75 | key = unquote(key) 76 | value = unquote(value) 77 | if key in query: 78 | query[key].append(value) 79 | else: 80 | query[key] = [value] 81 | spl = url.split('/', 1) 82 | host = spl[0] 83 | if len(spl) > 1: 84 | url = '/' + spl[1] 85 | else: 86 | url = '/' 87 | 88 | self.scheme = scheme 89 | self.host = host 90 | self.uri = url 91 | self.query = query 92 | if headers is None: 93 | self.headers = {} 94 | else: 95 | self.headers = copy.deepcopy(headers) 96 | if sys.version_info.major < 3: 97 | self.body = body 98 | else: 99 | self.body = body.encode("utf-8") 100 | 101 | 102 | BasicDateFormat = "%Y%m%dT%H%M%SZ" 103 | Algorithm = "SDK-HMAC-SHA256" 104 | HeaderXDate = "X-Sdk-Date" 105 | HeaderHost = "host" 106 | HeaderAuthorization = "Authorization" 107 | HeaderContentSha256 = "x-sdk-content-sha256" 108 | 109 | 110 | # Build a CanonicalRequest from a regular request string 111 | # 112 | # CanonicalRequest = 113 | # HTTPRequestMethod + '\n' + 114 | # CanonicalURI + '\n' + 115 | # CanonicalQueryString + '\n' + 116 | # CanonicalHeaders + '\n' + 117 | # SignedHeaders + '\n' + 118 | # HexEncode(Hash(RequestPayload)) 119 | def CanonicalRequest(r, signedHeaders): 120 | canonicalHeaders = CanonicalHeaders(r, signedHeaders) 121 | hexencode = findHeader(r, HeaderContentSha256) 122 | if hexencode is None: 123 | hexencode = HexEncodeSHA256Hash(r.body) 124 | return "%s\n%s\n%s\n%s\n%s\n%s" % (r.method.upper(), CanonicalURI(r), CanonicalQueryString(r), 125 | canonicalHeaders, ";".join(signedHeaders), hexencode) 126 | 127 | 128 | def CanonicalURI(r): 129 | pattens = unquote(r.uri).split('/') 130 | uri = [] 131 | for v in pattens: 132 | uri.append(urlencode(v)) 133 | urlpath = "/".join(uri) 134 | if urlpath[-1] != '/': 135 | urlpath = urlpath + "/" # always end with / 136 | # r.uri = urlpath 137 | return urlpath 138 | 139 | 140 | def CanonicalQueryString(r): 141 | keys = [] 142 | for key in r.query: 143 | keys.append(key) 144 | keys.sort() 145 | a = [] 146 | for key in keys: 147 | k = urlencode(key) 148 | value = r.query[key] 149 | if type(value) is list: 150 | value.sort() 151 | for v in value: 152 | kv = k + "=" + urlencode(str(v)) 153 | a.append(kv) 154 | else: 155 | kv = k + "=" + urlencode(str(value)) 156 | a.append(kv) 157 | return '&'.join(a) 158 | 159 | 160 | def CanonicalHeaders(r, signedHeaders): 161 | a = [] 162 | __headers = {} 163 | for key in r.headers: 164 | keyEncoded = key.lower() 165 | value = r.headers[key] 166 | valueEncoded = value.strip() 167 | __headers[keyEncoded] = valueEncoded 168 | if sys.version_info.major == 3: 169 | r.headers[key] = valueEncoded.encode("utf-8").decode('iso-8859-1') 170 | for key in signedHeaders: 171 | a.append(key + ":" + __headers[key]) 172 | return '\n'.join(a) + "\n" 173 | 174 | 175 | def SignedHeaders(r): 176 | a = [] 177 | for key in r.headers: 178 | a.append(key.lower()) 179 | a.sort() 180 | return a 181 | 182 | 183 | # Create the HWS Signature. 184 | def SignStringToSign(stringToSign, signingKey): 185 | hm = hmacsha256(signingKey, stringToSign) 186 | return binascii.hexlify(hm).decode() 187 | 188 | 189 | # Get the finalized value for the "Authorization" header. The signature 190 | # parameter is the output from SignStringToSign 191 | def AuthHeaderValue(signature, AppKey, signedHeaders): 192 | return "%s Access=%s, SignedHeaders=%s, Signature=%s" % ( 193 | Algorithm, AppKey, ";".join(signedHeaders), signature) 194 | 195 | 196 | class Signer: 197 | def __init__(self): 198 | self.Key = "" 199 | self.Secret = "" 200 | 201 | def Verify(self, r, authorization): 202 | if sys.version_info.major == 3 and isinstance(r.body, str): 203 | r.body = r.body.encode('utf-8') 204 | headerTime = findHeader(r, HeaderXDate) 205 | if headerTime is None: 206 | return False 207 | else: 208 | t = datetime.strptime(headerTime, BasicDateFormat) 209 | 210 | signedHeaders = SignedHeaders(r) 211 | canonicalRequest = CanonicalRequest(r, signedHeaders) 212 | stringToSign = StringToSign(canonicalRequest, t) 213 | return authorization == SignStringToSign(stringToSign, self.Secret) 214 | 215 | # SignRequest set Authorization header 216 | def Sign(self, r): 217 | if sys.version_info.major == 3 and isinstance(r.body, str): 218 | r.body = r.body.encode('utf-8') 219 | headerTime = findHeader(r, HeaderXDate) 220 | if headerTime is None: 221 | t = datetime.utcnow() 222 | r.headers[HeaderXDate] = datetime.strftime(t, BasicDateFormat) 223 | else: 224 | t = datetime.strptime(headerTime, BasicDateFormat) 225 | 226 | haveHost = False 227 | for key in r.headers: 228 | if key.lower() == 'host': 229 | haveHost = True 230 | break 231 | if not haveHost: 232 | r.headers["host"] = r.host 233 | signedHeaders = SignedHeaders(r) 234 | canonicalRequest = CanonicalRequest(r, signedHeaders) 235 | stringToSign = StringToSign(canonicalRequest, t) 236 | signature = SignStringToSign(stringToSign, self.Secret) 237 | authValue = AuthHeaderValue(signature, self.Key, signedHeaders) 238 | r.headers[HeaderAuthorization] = authValue 239 | r.headers["content-length"] = str(len(r.body)) 240 | queryString = CanonicalQueryString(r) 241 | if queryString != "": 242 | r.uri = r.uri + "?" + queryString 243 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/auth/token_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.utils import http_utils 4 | from huaweicloud_sis.bean.sis_config import SisConfig 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | from huaweicloud_sis.utils.logger_utils import logger 7 | 8 | 9 | def get_token(user_name, password, domain_name, region, url=None, config=SisConfig()): 10 | """ 11 | 获取token 12 | :param user_name: 用户名 13 | :param password: 密码 14 | :param domain_name: 账户名,一般等同用户名 15 | :param region: 区域,如cn-north-4 16 | :param url: 请求token的url,可使用默认值 17 | :param config 配置信息 18 | :return: 请求的token 19 | """ 20 | if url is None: 21 | url = 'https://iam.' + region + '.myhuaweicloud.com/v3/auth/tokens' 22 | if not isinstance(config, SisConfig): 23 | error_msg = 'the param \'config\' in token_service must be SisConfig class' 24 | logger.error(error_msg) 25 | raise ClientException(error_msg) 26 | time_out = (config.get_connect_timeout(), config.get_read_timeout()) 27 | proxy = config.get_proxy() 28 | auth_data = { 29 | "auth": { 30 | "identity": { 31 | "password": { 32 | "user": { 33 | "name": user_name, 34 | "password": password, 35 | "domain": { 36 | "name": domain_name 37 | } 38 | } 39 | }, 40 | "methods": [ 41 | "password" 42 | ] 43 | }, 44 | "scope": { 45 | "project": { 46 | "name": region 47 | } 48 | } 49 | } 50 | } 51 | 52 | headers = {'Content-Type': 'application/json'} 53 | req = http_utils.http_connect(url, headers, auth_data, 'POST', time_out, proxy, config.get_certificate_check()) 54 | if 'X-Subject-Token' not in req.headers: 55 | logger.error('Error occurs in getting token, %s' % req.text) 56 | raise ClientException('Error occurs in getting token, %s' % req.text) 57 | token = req.headers['X-Subject-Token'] 58 | return token 59 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/asr_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from huaweicloud_sis.bean.rasr_request import RasrRequest 3 | 4 | class AsrCustomShortRequest: 5 | """ 一句话识别请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | def __init__(self, audio_format, model_property, data): 7 | """ 8 | 一句话识别请求初始化 9 | :param audio_format: 音频格式,详见api文档 10 | :param model_property: language_sampleRate_domain, 如chinese_8k_common, 详见api文档 11 | :param data: 音频转化后的base64字符串 12 | """ 13 | self._audio_format = audio_format 14 | self._property = model_property 15 | self._data = data 16 | self._add_punc = 'no' 17 | self._digit_norm = 'yes' 18 | self._vocabulary_id = None 19 | self._need_word_info = 'no' 20 | self._user_words = list() 21 | 22 | def set_add_punc(self, add_punc): 23 | self._add_punc = add_punc 24 | 25 | def set_digit_norm(self, digit_norm): 26 | self._digit_norm = digit_norm 27 | 28 | def set_vocabulary_id(self, vocabulary_id): 29 | self._vocabulary_id = vocabulary_id 30 | 31 | def set_need_word_info(self, need_word_info): 32 | self._need_word_info = need_word_info 33 | 34 | def set_user_words(self, user_words): 35 | self._user_words = user_words 36 | 37 | def construct_params(self): 38 | params = dict() 39 | params['data'] = self._data 40 | config = dict() 41 | config['audio_format'] = self._audio_format 42 | config['property'] = self._property 43 | config['add_punc'] = self._add_punc 44 | config['digit_norm'] = self._digit_norm 45 | config['need_word_info'] = self._need_word_info 46 | if self._vocabulary_id is not None: 47 | config['vocabulary_id'] = self._vocabulary_id 48 | if self._user_words is not None and len(self._user_words) > 0: 49 | config['user_words'] = self._user_words 50 | params['config'] = config 51 | return params 52 | 53 | 54 | class AsrCustomLongRequest: 55 | """ 录音文件识别请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 56 | def __init__(self, audio_format, model_property, data_url): 57 | """ 58 | 录音文件识别初始化 59 | :param audio_format: 音频格式,详见api文档 60 | :param model_property: 属性字符串,language_sampleRate_domain, 详见api文档 61 | :param data_url: 音频的obs链接 62 | """ 63 | self._audio_format = audio_format 64 | self._property = model_property 65 | self._data_url = data_url 66 | self._add_punc = 'no' 67 | self._digit_norm = 'yes' 68 | self._callback_url = None 69 | self._need_analysis_info = False 70 | self._diarization = True 71 | self._channel = 'MONO' 72 | self._emotion = True 73 | self._speed = True 74 | self._vocabulary_id = None 75 | self._need_word_info = 'no' 76 | 77 | def set_callback_url(self, callback_url): 78 | self._callback_url = callback_url 79 | 80 | def set_add_punc(self, add_punc): 81 | self._add_punc = add_punc 82 | 83 | def set_digit_norm(self, digit_norm): 84 | self._digit_norm = digit_norm 85 | 86 | def set_need_analysis_info(self, need_analysis_info): 87 | self._need_analysis_info = need_analysis_info 88 | 89 | def set_diarization(self, diarization): 90 | self._diarization = diarization 91 | 92 | def set_channel(self, channel): 93 | self._channel = channel 94 | 95 | def set_emotion(self, emotion): 96 | self._emotion = emotion 97 | 98 | def set_speed(self, speed): 99 | self._speed = speed 100 | 101 | def set_vocabulary_id(self, vocabulary_id): 102 | self._vocabulary_id = vocabulary_id 103 | 104 | def set_need_word_info(self, need_word_info): 105 | self._need_word_info = need_word_info 106 | 107 | def construct_parameter(self): 108 | params = dict() 109 | params['data_url'] = self._data_url 110 | config = dict() 111 | config['audio_format'] = self._audio_format 112 | config['property'] = self._property 113 | config['add_punc'] = self._add_punc 114 | config['digit_norm'] = self._digit_norm 115 | config['need_word_info'] = self._need_word_info 116 | if self._callback_url is not None and not self._callback_url == '': 117 | config['callback_url'] = self._callback_url 118 | if self._need_analysis_info: 119 | need_analysis_info = dict() 120 | need_analysis_info['diarization'] = self._diarization 121 | need_analysis_info['channel'] = self._channel 122 | need_analysis_info['emotion'] = self._emotion 123 | need_analysis_info['speed'] = self._speed 124 | config['need_analysis_info'] = need_analysis_info 125 | if self._vocabulary_id is not None: 126 | config['vocabulary_id'] = self._vocabulary_id 127 | params['config'] = config 128 | return params 129 | 130 | 131 | class SasrWebsocketRequest(RasrRequest): 132 | def __init__(self, audio_format, model_property): 133 | super().__init__(audio_format, model_property) 134 | 135 | def construct_params(self): 136 | result = super().construct_params() 137 | remove_list = ['vad_head', 'vad_tail', 'max_seconds'] 138 | for key in remove_list: 139 | if key in result: 140 | del result[key] 141 | return result 142 | 143 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/callback.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # -*- coding: utf-8 -*- 3 | 4 | from huaweicloud_sis.utils.logger_utils import logger 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | 7 | 8 | class RasrCallBack: 9 | """ 实时语音识别的监听接口,监听创立链接、开始、中间响应、结束、关闭连接、错误 """ 10 | def on_open(self): 11 | logger.debug('websocket connect success') 12 | 13 | def on_start(self, message): 14 | logger.debug('websocket start, %s' % message) 15 | 16 | def on_response(self, message): 17 | raise ClientException('no response implementation') 18 | 19 | def on_end(self, message): 20 | logger.debug('websocket end, %s' % message) 21 | 22 | def on_close(self): 23 | logger.debug('websocket close') 24 | 25 | def on_error(self, error): 26 | logger.error(error) 27 | 28 | def on_event(self, event): 29 | logger.info("receive event %s" % event) 30 | 31 | 32 | class RttsCallBack: 33 | def on_close(self): 34 | logger.debug('websocket close') 35 | 36 | def on_open(self): 37 | logger.debug('websocket connect success') 38 | 39 | def on_start(self, message): 40 | logger.debug('websocket start, %s' % message) 41 | 42 | def on_response(self, data): 43 | raise ClientException('no response implementation') 44 | 45 | def on_end(self, message): 46 | logger.debug('websocket end, %s' % message) 47 | 48 | def on_error(self, error): 49 | logger.error(error) 50 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/flash_lasr_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | class FlashLasrRequest: 4 | def __init__(self): 5 | self._audio_format = None 6 | self._property = None 7 | self._add_punc = 'no' 8 | self._digit_norm = 'no' 9 | self._vocabulary_id = None 10 | self._need_word_info = 'no' 11 | self._first_channel_only = 'no' 12 | self._obs_bucket_name = None 13 | self._obs_object_key = None 14 | 15 | def set_audio_format(self, audio_format): 16 | self._audio_format = audio_format 17 | 18 | def set_property(self, property): 19 | self._property = property 20 | 21 | def set_add_punc(self, add_punc): 22 | self._add_punc = add_punc 23 | 24 | def set_digit_norm(self, digit_norm): 25 | self._digit_norm = digit_norm 26 | 27 | def set_vocabulary_id(self, vocabulary_id): 28 | self._vocabulary_id = vocabulary_id 29 | 30 | def set_need_word_info(self, need_word_info): 31 | self._need_word_info = need_word_info 32 | 33 | def set_first_channel_only(self, first_channel_only): 34 | self._first_channel_only = first_channel_only 35 | 36 | def set_obs_bucket_name(self, obs_bucket_name): 37 | self._obs_bucket_name = obs_bucket_name 38 | 39 | def set_obs_object_key(self, obs_object_key): 40 | self._obs_object_key = obs_object_key 41 | 42 | def construct_params(self): 43 | params = '?' 44 | if self._audio_format is not None: 45 | params += '&audio_format=' + str(self._audio_format) 46 | if self._property is not None: 47 | params += '&property=' + str(self._property) 48 | params += '&add_punc=' + str(self._add_punc) 49 | params += '&digit_norm=' + str(self._digit_norm) 50 | 51 | if self._vocabulary_id is not None: 52 | params += '&vocabulary_id=' + str(self._vocabulary_id) 53 | params += '&need_word_info=' + str(self._need_word_info) 54 | params += '&first_channel_only=' + str(self._first_channel_only) 55 | if self._obs_bucket_name is not None: 56 | params += '&obs_bucket_name=' + str(self._obs_bucket_name) 57 | if self._obs_object_key is not None: 58 | params += '&obs_object_key=' + str(self._obs_object_key) 59 | return params 60 | 61 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/hot_word_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class HotWordRequest: 5 | def __init__(self, name, word_list): 6 | self._name = name 7 | self._word_list = word_list 8 | self._language = 'chinese_mandarin' 9 | self._description = '' 10 | 11 | def set_description(self, description): 12 | self._description = description 13 | 14 | def set_language(self, language): 15 | self._language = language 16 | 17 | def construct_params(self): 18 | params_dict = { 19 | 'name': self._name, 20 | 'language': self._language, 21 | 'description': self._description, 22 | 'contents': self._word_list 23 | } 24 | return params_dict 25 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/pa_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.utils.logger_utils import logger 4 | from huaweicloud_sis.exception.exceptions import ClientException 5 | 6 | 7 | class PaAudioRequest: 8 | """ 语音评测请求 """ 9 | def __init__(self): 10 | """ 11 | 语音请求初始化 12 | """ 13 | self._audio_data = None 14 | self._audio_url = None 15 | self._ref_text = None 16 | self._audio_format = 'auto' 17 | self._language = 'en_gb' 18 | self._mode = 'word' 19 | 20 | def set_audio_data(self, audio_data): 21 | self._audio_data = audio_data 22 | 23 | def set_audio_url(self, audio_url): 24 | self._audio_url = audio_url 25 | 26 | def set_audio_format(self, audio_format): 27 | self._audio_format = audio_format 28 | 29 | def set_ref_text(self, ref_text): 30 | self._ref_text = ref_text 31 | 32 | def set_language(self, language): 33 | self._language = language 34 | 35 | def set_mode(self, mode): 36 | self._mode = mode 37 | 38 | def construct_params(self): 39 | if self._audio_data is None and self._audio_url is None: 40 | logger.error('In PaAudioRequest, audio_data and audio_url can\'t be both empty') 41 | raise ClientException('In PaAudioRequest, audio_data and audio_url can\'t be both empty') 42 | if self._ref_text is None: 43 | logger.error('In PaAudioRequest, ref_text can\'t be empty') 44 | raise ClientException('In PaAudioRequest, ref_text can\'t be empty') 45 | if self._audio_data is not None and self._audio_url is not None: 46 | logger.warn('When audio_data and audio_url are all filled, only audio_data takes effect') 47 | params_dict = { 48 | 'ref_text': self._ref_text, 49 | 'config': { 50 | 'audio_format': self._audio_format, 51 | 'language': self._language, 52 | 'mode': self._mode 53 | } 54 | } 55 | if self._audio_data is not None: 56 | params_dict['audio_data'] = self._audio_data 57 | else: 58 | params_dict['audio_url'] = self._audio_url 59 | return params_dict 60 | 61 | 62 | class PaVideoRequest: 63 | def __init__(self): 64 | """ 65 | 多模态评测请求 66 | 67 | """ 68 | self._video_data = None 69 | self._video_url = None 70 | self._video_format = 'auto' 71 | self._ref_text = None 72 | self._language = 'en_gb' 73 | self._mode = 'word' 74 | 75 | def set_video_data(self, video_data): 76 | self._video_data = video_data 77 | 78 | def set_video_url(self, video_url): 79 | self._video_url = video_url 80 | 81 | def set_video_format(self, video_format): 82 | self._video_format = video_format 83 | 84 | def set_ref_text(self, ref_text): 85 | self._ref_text = ref_text 86 | 87 | def set_language(self, language): 88 | self._language = language 89 | 90 | def set_mode(self, mode): 91 | self._mode = mode 92 | 93 | def construct_parameter(self): 94 | if self._video_data is None and self._video_url is None: 95 | logger.error('In PaVideoRequest, video_data and video_url can\'t be both empty') 96 | raise ClientException('In PaVideoRequest, video_data and video_url can\'t be both empty') 97 | if self._ref_text is None: 98 | logger.error('In PaVideoRequest, ref_text can\'t be empty') 99 | raise ClientException('In PaVideoRequest, ref_text can\'t be empty') 100 | if self._video_data is not None and self._video_url is not None: 101 | logger.warn('When video_data and video_url are all filled, only video_data takes effect') 102 | params_dict = { 103 | 'ref_text': self._ref_text, 104 | 'config': { 105 | 'video_format': self._video_format, 106 | 'language': self._language, 107 | 'mode': self._mode 108 | } 109 | } 110 | if self._video_data is not None: 111 | params_dict['video_data'] = self._video_data 112 | else: 113 | params_dict['video_url'] = self._video_url 114 | return params_dict 115 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/rasr_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class RasrRequest: 5 | """ 实时语音识别请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | def __init__(self, audio_format, model_property): 7 | """ 8 | 实时语音识别请求初始化 9 | :param audio_format: 音频格式,详见api文档 10 | :param model_property: 属性字符串,language_sampleRate_domain, 如chinese_8k_common,详见api文档 11 | """ 12 | self._audio_format = audio_format 13 | self._property = model_property 14 | self._add_punc = 'no' 15 | self._vad_head = 10000 16 | self._vad_tail = 500 17 | self._max_seconds = 30 18 | self._interim_results = 'no' 19 | self._digit_norm = 'yes' 20 | self._vocabulary_id = None 21 | self._vad_threshold = 0 22 | self._user_words = [] 23 | self._need_word_info = 'no' 24 | 25 | def set_add_punc(self, add_punc): 26 | self._add_punc = add_punc 27 | 28 | def set_digit_norm(self, digit_norm): 29 | self._digit_norm = digit_norm 30 | 31 | def set_vad_head(self, vad_head): 32 | self._vad_head = vad_head 33 | 34 | def set_vad_tail(self, vad_tail): 35 | self._vad_tail = vad_tail 36 | 37 | def set_max_seconds(self, max_seconds): 38 | self._max_seconds = max_seconds 39 | 40 | def set_interim_results(self, interim_results): 41 | self._interim_results = interim_results 42 | 43 | def set_vocabulary_id(self, vocabulary_id): 44 | self._vocabulary_id = vocabulary_id 45 | 46 | def set_vad_threshold(self, vad_threshold): 47 | self._vad_threshold = vad_threshold 48 | 49 | def set_user_words(self, user_words): 50 | self._user_words = user_words 51 | 52 | def set_need_word_info(self, need_word_info): 53 | self._need_word_info = need_word_info 54 | 55 | def construct_params(self): 56 | config = dict() 57 | config['audio_format'] = self._audio_format 58 | config['property'] = self._property 59 | config['add_punc'] = self._add_punc 60 | config['digit_norm'] = self._digit_norm 61 | config['vad_head'] = self._vad_head 62 | config['vad_tail'] = self._vad_tail 63 | config['max_seconds'] = self._max_seconds 64 | config['interim_results'] = self._interim_results 65 | config['vad_threshold'] = self._vad_threshold 66 | config['need_word_info'] = self._need_word_info 67 | if self._user_words is not None and len(self._user_words) > 0: 68 | config['user_words'] = self._user_words 69 | if self._vocabulary_id is not None: 70 | config['vocabulary_id'] = self._vocabulary_id 71 | 72 | params = dict() 73 | params['command'] = 'START' 74 | params['config'] = config 75 | return params 76 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/rtts_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class RttsRequest: 5 | """ 实时语音转写请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | 7 | def __init__(self, text): 8 | """ 9 | 实时语音转写请求初始化 10 | :param audio_format: 音频格式,详见api文档 11 | :param model_property: 属性字符串,language_sampleRate_domain, 如chinese_8k_common,详见api文档 12 | """ 13 | self._text = text 14 | self._command = 'START' 15 | self._audio_format = 'pcm' 16 | self._sample_rate = '8000' 17 | self._property = 'chinese_xiaoyan_common' 18 | self._speed = 0 19 | self._pitch = 0 20 | self._volume = 50 21 | 22 | def set_command(self, command): 23 | self._command = command 24 | 25 | def set_audio_format(self, audio_format): 26 | self._audio_format = audio_format 27 | 28 | def set_sample_rate(self, sample_rate): 29 | self._sample_rate = sample_rate 30 | 31 | def set_property(self, property): 32 | self._property = property 33 | 34 | def set_speed(self, speed): 35 | self._speed = speed 36 | 37 | def set_pitch(self, pitch): 38 | self._pitch = pitch 39 | 40 | def set_volume(self, volume): 41 | self._volume = volume 42 | 43 | def construct_params(self): 44 | config = dict() 45 | config['speed'] = self._speed 46 | config['pitch'] = self._pitch 47 | config['audio_format'] = self._audio_format 48 | config['sample_rate'] = self._sample_rate 49 | config['property'] = self._property 50 | config['volume'] = self._volume 51 | 52 | params = dict() 53 | params['command'] = self._command 54 | params['config'] = config 55 | params['text'] = self._text 56 | return params 57 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/sis_config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class SisConfig: 5 | """ client配置参数,包括超时、代理 """ 6 | def __init__(self): 7 | self.connect_timeout = 10 8 | self.read_timeout = 10 9 | self.connect_lost_timeout = 10 10 | self.proxy = None 11 | self.certificate_check = False 12 | 13 | def set_certificate_check(self, certificate_check): 14 | self.certificate_check = certificate_check 15 | 16 | def get_certificate_check(self): 17 | return self.certificate_check 18 | 19 | def set_connect_timeout(self, timeout): 20 | """ 21 | 设置连接超时 22 | :param timeout: seconds 23 | """ 24 | self.connect_timeout = timeout 25 | 26 | def get_connect_timeout(self): 27 | """ 28 | 返回连接超时时间 29 | :return: connect_timeout, 单位秒 30 | """ 31 | return self.connect_timeout 32 | 33 | def set_read_timeout(self, timeout): 34 | """ 35 | 设置读取超时 36 | :param timeout: seconds 37 | """ 38 | self.read_timeout = timeout 39 | 40 | def get_read_timeout(self): 41 | """ 42 | 返回读取超时 43 | :return: read_timeout, 单位秒 44 | """ 45 | return self.read_timeout 46 | 47 | def set_proxy(self, proxy): 48 | """ 49 | 设置代理 50 | :param proxy: 格式为list,[host, port] 或 [host, port, username, password] 51 | """ 52 | self.proxy = proxy 53 | 54 | def get_proxy(self): 55 | """ 56 | 返回代理 57 | :return: proxy 58 | """ 59 | return self.proxy 60 | 61 | def set_connect_lost_timeout(self, timeout): 62 | """ 63 | 设置connect lost 超时, 在并发满足要求下不需要设置此参数 64 | :param timeout: seconds 65 | """ 66 | self.connect_lost_timeout = timeout 67 | 68 | def get_connect_lost_timeout(self): 69 | """ 70 | 返回connnect lost超时 71 | :return: connect_lost_timeout, 单位秒 72 | """ 73 | return self.connect_lost_timeout 74 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/bean/tts_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class TtsCustomRequest: 5 | """ 语音合成请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | def __init__(self, text): 7 | """ 8 | 语音合成请求初始化 9 | :param text: 需要合成的文本 10 | """ 11 | self._text = text 12 | self._audio_format = 'wav' 13 | self._property = 'chinese_xiaoyan_common' 14 | self._sample_rate = '8000' 15 | self._speed = 0 16 | self._pitch = 0 17 | self._volume = 50 18 | self._saved = False 19 | self._saved_path = '' 20 | 21 | def set_audio_format(self, audio_format): 22 | self._audio_format = audio_format 23 | 24 | def set_volume(self, volume): 25 | self._volume = volume 26 | 27 | def set_sample_rate(self, sample_rate): 28 | self._sample_rate = sample_rate 29 | 30 | def set_property(self, model_property): 31 | self._property = model_property 32 | 33 | def set_pitch(self, pitch): 34 | self._pitch = pitch 35 | 36 | def set_speed(self, speed): 37 | self._speed = speed 38 | 39 | def set_saved(self, saved): 40 | self._saved = saved 41 | 42 | def set_saved_path(self, saved_path): 43 | self._saved_path = saved_path 44 | 45 | def get_saved(self): 46 | return self._saved 47 | 48 | def get_saved_path(self): 49 | return self._saved_path 50 | 51 | def construct_params(self): 52 | config = dict() 53 | config['audio_format'] = self._audio_format 54 | config['sample_rate'] = self._sample_rate 55 | config['property'] = self._property 56 | config['speed'] = self._speed 57 | config['pitch'] = self._pitch 58 | config['volume'] = self._volume 59 | 60 | params = dict() 61 | params['text'] = self._text 62 | params['config'] = config 63 | return params 64 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/client/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/client/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/client/asr_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.auth import aksk_service 4 | from huaweicloud_sis.bean.asr_request import AsrCustomLongRequest 5 | from huaweicloud_sis.bean.asr_request import AsrCustomShortRequest 6 | from huaweicloud_sis.utils.logger_utils import logger 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | from huaweicloud_sis.client.rasr_client import RasrClient 10 | 11 | 12 | class AsrCustomizationClient: 13 | """ 语音识别client """ 14 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 15 | """ 16 | 语音识别client初始化 17 | :param ak: ak 18 | :param sk: sk 19 | :param region: 区域,如cn-north-4 20 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 21 | :param service_endpoint: 终端节点,可不填使用默认即可 22 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 23 | """ 24 | self._ak = ak 25 | self._sk = sk 26 | self._region = region 27 | self._project_id = project_id 28 | if service_endpoint is None: 29 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 30 | else: 31 | self._service_endpoint = service_endpoint 32 | if sis_config is None: 33 | self._sis_config = SisConfig() 34 | else: 35 | self._sis_config = sis_config 36 | 37 | def get_short_response(self, request): 38 | """ 39 | 一句话识别接口 40 | :param request: 一句话识别请求AsrCustomShortRequest 41 | :return: 一句话识别响应结果,返回为json格式 42 | """ 43 | if not isinstance(request, AsrCustomShortRequest): 44 | error_msg = 'the parameter in \'get_short_response(request)\' should be AsrCustomShortRequest class' 45 | logger.error(error_msg) 46 | raise ClientException(error_msg) 47 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/short-audio' 48 | params = request.construct_params() 49 | headers = {'Content-Type': 'application/json'} 50 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 51 | return result 52 | 53 | def submit_job(self, request): 54 | """ 55 | 录音文件识别,提交任务接口 56 | :param request: 录音文件识别请求 57 | :return: job_id 58 | """ 59 | if not isinstance(request, AsrCustomLongRequest): 60 | error_msg = 'the parameter in \'submit_job(request)\' should be AsrCustomLongRequest class' 61 | logger.error(error_msg) 62 | raise ClientException(error_msg) 63 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/transcriber/jobs' 64 | headers = {'Content-Type': 'application/json'} 65 | params = request.construct_parameter() 66 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 67 | if 'job_id' not in result: 68 | error_msg = 'The result of long audio transcription doesn\'t contain key job_id, result is ' % result 69 | logger.error(error_msg) 70 | raise ClientException(error_msg) 71 | return result['job_id'] 72 | 73 | def get_long_response(self, job_id): 74 | """ 75 | 录音文件识别状态查询接口 76 | :param job_id: job_id 77 | :return: 返回的结果,json格式 78 | """ 79 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/transcriber/jobs/' + job_id 80 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'GET', self._sis_config) 81 | return result 82 | 83 | 84 | class SasrWebsocketClient(RasrClient): 85 | def __init__(self, user_name=None, password=None, domain_name=None, region=None, project_id=None, callback=None, 86 | config=SisConfig(), service_endpoint=None, token_url=None, retry_sleep_time=1, ak=None, sk=None, 87 | use_aksk=False): 88 | super().__init__(user_name, password, domain_name, region, project_id, callback, config, service_endpoint, 89 | token_url, retry_sleep_time, ak, sk, use_aksk) -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/client/flash_lasr_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.bean.sis_config import SisConfig 4 | from huaweicloud_sis.bean.flash_lasr_request import FlashLasrRequest 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.exception.exceptions import ClientException 7 | from huaweicloud_sis.auth import aksk_service 8 | 9 | 10 | class FlashLasrClient: 11 | """ 录音文件极速版 client """ 12 | 13 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 14 | """ 15 | 录音文件极速版client初始化 16 | :param ak: ak 17 | :param sk: sk 18 | :param region: 区域,如cn-north-4 19 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 20 | :param service_endpoint: 终端节点,可不填使用默认即可 21 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 22 | """ 23 | self._ak = ak 24 | self._sk = sk 25 | self._region = region 26 | self._project_id = project_id 27 | if service_endpoint is None: 28 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 29 | else: 30 | self._service_endpoint = service_endpoint 31 | if sis_config is None: 32 | self._sis_config = SisConfig() 33 | else: 34 | self._sis_config = sis_config 35 | 36 | def get_flash_lasr_result(self, request): 37 | """ 38 | 录音文件极速版接口 39 | :param request: 录音文件极速版请求 40 | :return: 响应结果,返回为json格式 41 | """ 42 | if not isinstance(request, FlashLasrRequest): 43 | error_msg = 'the parameter in flash lasr should be FlashLasrRequest class' 44 | logger.error(error_msg) 45 | raise ClientException(error_msg) 46 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/flash' 47 | query_url = url + request.construct_params() 48 | headers = {'Content-Type': 'application/json'} 49 | result = aksk_service.aksk_connect(self._ak, self._sk, query_url, headers, None, 'POST', self._sis_config) 50 | return result -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/client/hot_word_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.bean.hot_word_request import HotWordRequest 4 | from huaweicloud_sis.bean.sis_config import SisConfig 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.auth import aksk_service 7 | from huaweicloud_sis.exception.exceptions import ClientException, ServerException 8 | import json 9 | 10 | 11 | class HotWordClient: 12 | """ 热词client,可用于创建热词表、更新热词表、查询热词表列表、查询热词表、删除热词表 """ 13 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 14 | """ 15 | 口语评测client初始化 16 | :param ak: ak 17 | :param sk: sk 18 | :param region: 区域,如cn-north-4 19 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 20 | :param service_endpoint: 终端节点,可不填使用默认即可 21 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 22 | """ 23 | self._ak = ak 24 | self._sk = sk 25 | self._region = region 26 | self._project_id = project_id 27 | if service_endpoint is None: 28 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 29 | else: 30 | self._service_endpoint = service_endpoint 31 | if sis_config is None: 32 | self._sis_config = SisConfig() 33 | else: 34 | self._sis_config = sis_config 35 | 36 | def create(self, request): 37 | """ 38 | 创建热词表 39 | :param request: 热词表请求 40 | :return: 热词表id 41 | """ 42 | if not isinstance(request, HotWordRequest): 43 | logger.error('the parameter in \'create_hot_word(request)\' should be HotWordRequest class') 44 | raise ClientException('the parameter in \'create_hot_word(request)\' should be HotWordRequest class') 45 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies' 46 | headers = {'Content-Type': 'application/json'} 47 | params = request.construct_params() 48 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 49 | return result 50 | 51 | def update(self, request, vocabulary_id): 52 | """ 53 | 更新热词表 54 | :param request: 热词表请求 55 | :param vocabulary_id: 热词表id,更新时一定要保证该热词表存在 56 | :return: 热词表id 57 | """ 58 | if not isinstance(request, HotWordRequest): 59 | logger.error('the parameter in \'update_hot_word(request)\' should be HotWordRequest class') 60 | raise ClientException('the parameter in \'update_hot_word(request)\' should be HotWordRequest class') 61 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id 62 | headers = {'Content-Type': 'application/json'} 63 | params = request.construct_params() 64 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'PUT', self._sis_config) 65 | return result 66 | 67 | def query_list(self): 68 | """ 69 | 查询热词表列表信息 70 | :return: 热词表列表信息 71 | """ 72 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies' 73 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'GET', self._sis_config) 74 | return result 75 | 76 | def query_by_vocabulary_id(self, vocabulary_id): 77 | """ 78 | 根据vocabulary_id查询热词表信息 79 | :param vocabulary_id: 热词表id,使用前一定要保证其已存在。 80 | :return: 热词表信息 81 | """ 82 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id 83 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'GET', self._sis_config) 84 | return result 85 | 86 | def delete(self, vocabulary_id): 87 | """ 88 | 根据vocabulary_id删除指定的热词表 89 | :param vocabulary_id: 热词表id,使用前一定要保证其已存在。 90 | :return: 正常删除返回结果为空,出现错误则返回error_code和error_msg 91 | """ 92 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id 93 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'DELETE', self._sis_config) 94 | if result is None: 95 | return result 96 | result_text = result.text 97 | return json.loads(result_text) 98 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/client/pa_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.auth import aksk_service 4 | from huaweicloud_sis.bean.pa_request import PaAudioRequest 5 | from huaweicloud_sis.bean.pa_request import PaVideoRequest 6 | from huaweicloud_sis.utils.logger_utils import logger 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | 10 | 11 | class PaClient: 12 | """ 口语评测 client """ 13 | 14 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 15 | """ 16 | 口语评测client初始化 17 | :param ak: ak 18 | :param sk: sk 19 | :param region: 区域,如cn-north-4 20 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 21 | :param service_endpoint: 终端节点,可不填使用默认即可 22 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 23 | """ 24 | self._ak = ak 25 | self._sk = sk 26 | self._region = region 27 | self._project_id = project_id 28 | if service_endpoint is None: 29 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 30 | else: 31 | self._service_endpoint = service_endpoint 32 | if sis_config is None: 33 | self._sis_config = SisConfig() 34 | else: 35 | self._sis_config = sis_config 36 | 37 | def assessment_audio(self, request): 38 | """ 39 | 语音评测接口 40 | :param request: 语音评测请求 41 | :return: 响应结果,返回为json格式 42 | """ 43 | if not isinstance(request, PaAudioRequest): 44 | error_msg = 'the parameter in \'assessment_audio(request)\' should be PaAudioRequest class' 45 | logger.error(error_msg) 46 | raise ClientException(error_msg) 47 | url = self._service_endpoint + '/v1/' + self._project_id + '/assessment/audio' 48 | params = request.construct_params() 49 | headers = {'Content-Type': 'application/json'} 50 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 51 | return result 52 | 53 | def assessment_video(self, request): 54 | """ 55 | 多模态评测接口 56 | :param request: 多模态评测请求 57 | :return: 响应结果,返回为json格式 58 | """ 59 | if not isinstance(request, PaVideoRequest): 60 | error_msg = 'the parameter in \'assessment_video(request)\' should be PaVideoRequest class' 61 | logger.error(error_msg) 62 | raise ClientException(error_msg) 63 | url = self._service_endpoint + '/v1/' + self._project_id + '/assessment/video' 64 | headers = {'Content-Type': 'application/json'} 65 | params = request.construct_parameter() 66 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 67 | return result 68 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/client/tts_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import json 4 | from huaweicloud_sis.auth import aksk_service 5 | from huaweicloud_sis.bean.tts_request import TtsCustomRequest 6 | from huaweicloud_sis.utils import io_utils 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | from huaweicloud_sis.utils.logger_utils import logger 10 | 11 | 12 | class TtsCustomizationClient: 13 | """ 语音合成client """ 14 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 15 | self._ak = ak 16 | self._sk = sk 17 | self._region = region 18 | self._project_id = project_id 19 | if service_endpoint is None: 20 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 21 | else: 22 | self._service_endpoint = service_endpoint 23 | if sis_config is None: 24 | self._sis_config = SisConfig() 25 | else: 26 | self._sis_config = sis_config 27 | 28 | def get_ttsc_response(self, request): 29 | """ 30 | 语音合成接口 31 | :param request: 语音合成请求,TtsCustomRequest 32 | :return: 请求结果,json格式 33 | """ 34 | if not isinstance(request, TtsCustomRequest): 35 | logger.error('the parameter in \'get_ttsc_response(request)\' should be TtsCustomRequest class') 36 | raise ClientException('the parameter in \'get_ttsc_response(request)\' should be TtsCustomRequest class') 37 | url = self._service_endpoint + '/v1/' + self._project_id + '/tts' 38 | params = request.construct_params() 39 | headers = {'Content-Type': 'application/json'} 40 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 41 | if 'result' not in result: 42 | error_msg = 'The result of tts customization is invalid. Result is %s ' % json.dumps(result) 43 | logger.error(error_msg) 44 | raise ClientException(error_msg) 45 | if request.get_saved(): 46 | base_str = result['result']['data'] 47 | io_utils.save_audio_from_base64str(base_str, request.get_saved_path()) 48 | result['is_saved'] = True 49 | result['saved_path'] = request.get_saved_path() 50 | return result 51 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/exception/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/exception/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/exception/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class ClientException(Exception): 5 | def __init__(self, error_msg): 6 | super().__init__(self, error_msg) 7 | self._error_msg = error_msg 8 | 9 | def get_error_msg(self): 10 | return self._error_msg 11 | 12 | def __str__(self): 13 | return self.get_error_msg() 14 | 15 | 16 | class ServerException(Exception): 17 | def __init__(self, error_code, error_msg): 18 | dict1 = dict() 19 | dict1['error_code'] = error_code 20 | dict1['error_msg'] = error_msg 21 | super().__init__(self, str(dict1)) 22 | self._error_code = error_code 23 | self._error_msg = error_msg 24 | 25 | def get_error_code(self): 26 | return self._error_code 27 | 28 | def get_error_msg(self): 29 | return self._error_msg 30 | 31 | def __str__(self): 32 | return 'error_code: ' + self.get_error_code() + '\t' + 'error_msg: ' + self.get_error_msg() 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/utils/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/utils/http_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import requests 4 | import json 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.exception.exceptions import ClientException, ServerException 7 | 8 | requests.packages.urllib3.disable_warnings() 9 | NUM_MAX_RETRY = 5 10 | 11 | 12 | def http_connect(url, header, data, http_method='POST', time_out=5, proxy=None, certificate_check=False): 13 | """ 14 | post请求,带有header信息(用于认证) 15 | :param url: - 16 | :param header: 头部 17 | :param data: post数据 18 | :param time_out: 超时 19 | :param proxy: 代理 20 | :param http_method: http方法,目前支持put、delete、post、get 21 | :param certificate_check: 校验证书 22 | :return: http请求的response 23 | """ 24 | if isinstance(data, dict): 25 | data = json.dumps(data) 26 | if proxy is not None: 27 | proxy = _generate_request_proxy(proxy) 28 | else: 29 | proxy = { 30 | 'http': None, 31 | 'https': None 32 | } 33 | # 加入重试机制 34 | count = 0 35 | resp = None 36 | while count < NUM_MAX_RETRY: 37 | try: 38 | if http_method == 'POST': 39 | resp = requests.post(url, headers=header, data=data, timeout=time_out, verify=certificate_check, 40 | proxies=proxy) 41 | elif http_method == 'GET': 42 | resp = requests.get(url, headers=header, params=data, timeout=time_out, verify=certificate_check, 43 | proxies=proxy) 44 | elif http_method == 'PUT': 45 | resp = requests.put(url, headers=header, data=data, timeout=time_out, verify=certificate_check, 46 | proxies=proxy) 47 | elif http_method == 'DELETE': 48 | resp = requests.delete(url, headers=header, params=data, timeout=time_out, verify=certificate_check, 49 | proxies=proxy) 50 | else: 51 | logger.error('%s is invalid' % http_method) 52 | raise ClientException('%s is invalid' % http_method) 53 | break 54 | except requests.exceptions.RequestException as e: 55 | logger.error('Error occurs in %s, the client will retry 5 times. Error message is %s' % (http_method, e)) 56 | count += 1 57 | if resp is None: 58 | logger.error('%s Response is empety, url is %s' % (http_method, url)) 59 | raise ClientException('%s Response is empety, url is %s' % (http_method, url)) 60 | return resp 61 | 62 | 63 | def parse_resp(resp): 64 | """ 65 | requests响应转化为json格式 66 | :param resp: requests请求返回的响应 67 | :return: json 68 | """ 69 | if resp is None or resp.text is None or resp.text == '': 70 | return None 71 | text = resp.text 72 | try: 73 | result = json.loads(text) 74 | except Exception as e: 75 | error_msg = 'Parsing json failed, the text is %s' % text 76 | logger.error(error_msg) 77 | raise ClientException(error_msg) 78 | if 'error_code' in result and 'error_msg' in result: 79 | error_msg = json.dumps(result) 80 | logger.error(error_msg) 81 | raise ServerException(result['error_code'], result['error_msg']) 82 | return result 83 | 84 | 85 | def generate_scheme_host_uri(url): 86 | if url.find('//') == -1 or url.find('com') == -1: 87 | error_msg = '%s is invalid' % url 88 | logger.error(error_msg) 89 | raise ClientException(error_msg) 90 | split1s = url.split('//') 91 | split2s = split1s[1].split('com') 92 | scheme = split1s[0] + '//' 93 | host = split2s[0] + 'com' 94 | uri = split2s[1] 95 | return scheme, host, uri 96 | 97 | 98 | def _generate_request_proxy(proxy): 99 | if proxy is None: 100 | return proxy 101 | if not isinstance(proxy, list) or (not len(proxy) == 2 and not len(proxy) == 4): 102 | logger.error('Proxy must be list, the format is [host, port] or [host, port, username, password]') 103 | raise ClientException('Proxy must be list, the format is [host, port] or [host, port, username, password]') 104 | proxy_str = str(proxy[0]) + ':' + str(proxy[1]) 105 | if len(proxy) == 2: 106 | proxy = { 107 | 'http': 'http://' + proxy_str, 108 | 'https': 'https://' + proxy_str 109 | } 110 | else: 111 | proxy = { 112 | 'http': 'http://' + str(proxy[2]) + ':' + str(proxy[3]) + '@' + proxy_str, 113 | 'https': 'https://' + str(proxy[2]) + ':' + str(proxy[3]) + '@' + proxy_str 114 | } 115 | return proxy 116 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/utils/io_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import base64 4 | import os 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.exception.exceptions import ClientException 7 | 8 | 9 | def encode_file(file_path): 10 | if not os.path.exists(file_path): 11 | logger.error('The Path %s doesn\'t exist' % file_path) 12 | raise ClientException('The Path %s doesn\'t exist' % file_path) 13 | with open(file_path, 'rb') as f: 14 | data = f.read() 15 | base64_data = str(base64.b64encode(data), 'utf-8') 16 | return base64_data 17 | 18 | 19 | def save_audio_from_base64str(base64_str, save_path): 20 | parent_path = os.path.dirname(save_path) 21 | if parent_path != '' and not os.path.exists(parent_path): 22 | os.makedirs(parent_path) 23 | with open(save_path, 'wb') as f: 24 | base64_data = base64.b64decode(base64_str) 25 | f.write(base64_data) 26 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/build/lib/huaweicloud_sis/utils/logger_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import logging.handlers 4 | 5 | # 获取一个日志logger 6 | logging.basicConfig( 7 | level=logging.INFO, 8 | format='[%(asctime)s] - [%(levelname)s] - [%(message)s]' 9 | ) 10 | # 设置handler 11 | file_handler = logging.handlers.RotatingFileHandler('huaweicloud_sis.log', maxBytes=1024*1024, 12 | backupCount=5, encoding='utf-8') 13 | file_handler.setLevel(logging.INFO) 14 | file_handler.setFormatter(logging.Formatter('[%(asctime)s] - [%(levelname)s] - [%(message)s]')) 15 | 16 | # 添加file_handler 17 | logger = logging.getLogger('huaweicloud_sis') 18 | logger.addHandler(file_handler) 19 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/flash_lasr_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.flash_lasr_client import FlashLasrClient 4 | from huaweicloud_sis.bean.flash_lasr_request import FlashLasrRequest 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | from huaweicloud_sis.exception.exceptions import ServerException 7 | from huaweicloud_sis.bean.sis_config import SisConfig 8 | import json 9 | 10 | # 鉴权参数 11 | ak = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 12 | sk = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 13 | region = '' # region,如cn-north-4 14 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 15 | 16 | obs_bucket_name = '' # obs桶名 17 | obs_object_key = '' # obs对象的key 18 | property = '' # 文件格式,如wav等, 支持格式详见api文档 19 | audio_format = '' # 属性字符串,language_sampleRate_domain, 如chinese_8k_common, 详见api文档 20 | 21 | 22 | def flash_lasr_example(): 23 | """ 录音文件极速版示例 """ 24 | # step1 初始化客户端 25 | config = SisConfig() 26 | config.set_connect_timeout(10) # 设置连接超时 27 | config.set_read_timeout(10) # 设置读取超时 28 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 29 | # config.set_proxy(proxy) 30 | client = FlashLasrClient(ak, sk, region, project_id, sis_config=config) 31 | 32 | # step2 构造请求 33 | asr_request = FlashLasrRequest() 34 | # 以下参数必选 35 | # 设置存放音频的桶名,必选 36 | asr_request.set_obs_bucket_name(obs_bucket_name) 37 | # 设置桶内音频对象名,必选 38 | asr_request.set_obs_object_key(obs_object_key) 39 | # 设置格式,必选 40 | asr_request.set_audio_format(audio_format) 41 | # 设置属性,必选 42 | asr_request.set_property(property) 43 | 44 | # 以下参数可选 45 | # 设置是否添加标点,yes or no,默认no 46 | asr_request.set_add_punc('yes') 47 | # 设置是否将语音中数字转写为阿拉伯数字,yes or no,默认yes 48 | asr_request.set_digit_norm('yes') 49 | # 设置是否添加热词表id,没有则不填 50 | # asr_request.set_vocabulary_id(None) 51 | # 设置是否需要word_info,yes or no, 默认no 52 | asr_request.set_need_word_info('no') 53 | # 设置是否只识别收个声道的音频数据,默认no 54 | asr_request.set_first_channel_only('no') 55 | 56 | # step3 发送请求,返回结果,返回结果为json格式 57 | result = client.get_flash_lasr_result(asr_request) 58 | print(json.dumps(result, indent=2, ensure_ascii=False)) 59 | 60 | 61 | if __name__ == '__main__': 62 | try: 63 | flash_lasr_example() 64 | except ClientException as e: 65 | print(e) 66 | except ServerException as e: 67 | print(e) 68 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/hot_word_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.hot_word_client import HotWordClient 4 | from huaweicloud_sis.bean.hot_word_request import HotWordRequest 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | from huaweicloud_sis.exception.exceptions import ServerException 7 | from huaweicloud_sis.bean.sis_config import SisConfig 8 | import json 9 | 10 | # 鉴权参数 11 | ak = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 12 | sk = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 13 | region = '' # region,如cn-north-4 14 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 15 | 16 | 17 | # 热词参数 18 | name = '' # 创建热词时,需要保证name在此之前没有被创建使用过。如 test1 19 | word_list = list() # 用于存放热词表。每个热词表最多可以存放1024个热词。如["计算机", "网络"] 20 | vocabulary_id = '' # 用于更新指定热词表id信息,查询指定热词表id信息,删除指定热词表id信息。使用前要保证热词表id存在,否则就不要使用。 21 | 22 | 23 | def hot_word_example(): 24 | """ 25 | 1. 热词使用包含创建、更新、查询、删除等,一个用户可以创建多个热词表,一个热词表可以包含多个热词。一个vocabulary_id对应一个热词表。 26 | 2. 目前支持一个用户最多创建10个热词表,一个热词表最多包含1024个热词。 27 | 3. 热词可在一句话识别、录音文件识别、实时语音识别使用。例如将地名和人名作为热词,则语音可以准确识别出人名和地名。 28 | :return: 无 29 | """ 30 | # 初始化客户端 31 | config = SisConfig() 32 | config.set_connect_timeout(10) # 设置连接超时 33 | config.set_read_timeout(10) # 设置读取超时 34 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 35 | # config.set_proxy(proxy) 36 | hot_word_client = HotWordClient(ak, sk, region, project_id, sis_config=config) 37 | 38 | # option 1 创建热词表 39 | word_list.append('测试') 40 | create_request = HotWordRequest(name, word_list) 41 | # 可选,热词语言,目前仅支持中文 chinese_mandarin。 42 | create_request.set_language('chinese_mandarin') 43 | # 可选,热词表描述信息 44 | create_request.set_description('test') 45 | create_result = hot_word_client.create(create_request) 46 | # 返回结果为json格式 47 | print('成功创建热词表') 48 | print(json.dumps(create_result, indent=2, ensure_ascii=False)) 49 | 50 | # option 2 根据热词表id 更新热词表。新的热词表会替换旧的热词表。使用前需确保热词表id已存在。 51 | word_list.append('计算机') 52 | update_request = HotWordRequest('test2', word_list) 53 | update_result = hot_word_client.update(update_request, vocabulary_id) 54 | # 返回结果为json格式 55 | print('成功更新热词表', vocabulary_id) 56 | print(json.dumps(update_result, indent=2, ensure_ascii=False)) 57 | 58 | # option 3 查看热词表列表 59 | query_list_result = hot_word_client.query_list() 60 | print(json.dumps(query_list_result, indent=2, ensure_ascii=False)) 61 | 62 | # option 4 根据热词表id查询具体热词表信息,使用前需确保热词表id已存在。 63 | query_result = hot_word_client.query_by_vocabulary_id(vocabulary_id) 64 | print(json.dumps(query_result, indent=2, ensure_ascii=False)) 65 | 66 | # option 5 根据热词表id删除热词表,使用前需确保热词表id已存在。 67 | delete_result = hot_word_client.delete(vocabulary_id) 68 | if delete_result is None: 69 | print('成功删除热词表', vocabulary_id) 70 | else: 71 | print(json.dumps(delete_result, indent=2, ensure_ascii=False)) 72 | 73 | 74 | if __name__ == '__main__': 75 | try: 76 | hot_word_example() 77 | except ClientException as e: 78 | print(e) 79 | except ServerException as e: 80 | print(e) 81 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/lasr_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.asr_client import AsrCustomizationClient 4 | from huaweicloud_sis.bean.asr_request import AsrCustomLongRequest 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | from huaweicloud_sis.exception.exceptions import ServerException 7 | from huaweicloud_sis.bean.sis_config import SisConfig 8 | import json 9 | import time 10 | 11 | # 鉴权参数 12 | ak = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 13 | sk = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 14 | region = '' # region,如cn-north-4 15 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 16 | 17 | """ 18 | todo 请正确填写音频格式和模型属性字符串 19 | 1. 音频格式一定要相匹配. 20 | 例如wav音频,格式是auto。具体参考api文档。 21 | 例如音频是pcm格式,并且采样率为8k,则格式填写pcm8k16bit。 22 | 如果返回audio_format is invalid 说明该文件格式不支持。具体支持哪些音频格式,需要参考一些api文档。 23 | 24 | 2. 音频采样率要与属性字符串的采样率要匹配。 25 | 例如格式选择pcm16k16bit,属性字符串却选择chinese_8k_common, 则会返回'audio_format' is not match model 26 | 例如wav本身是16k采样率,属性选择chinese_8k_common, 同样会返回'audio_format' is not match model 27 | """ 28 | 29 | 30 | # 录音文件识别参数,音频文件以obs连接方式传入(即先需要将音频传送到华为云的obs) 31 | obs_url = '' # 音频obs连接 32 | obs_audio_format = '' # 音频格式,如auto等,详见api文档 33 | obs_property = '' # language_sampleRate_domain, 如chinese_8k_common,详见api文档 34 | 35 | 36 | def lasr_example(): 37 | """ 录音文件识别示例 """ 38 | # step1 初始化客户端 39 | config = SisConfig() 40 | config.set_connect_timeout(10) # 设置连接超时 41 | config.set_read_timeout(10) # 设置读取超时 42 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 43 | # config.set_proxy(proxy) 44 | asr_client = AsrCustomizationClient(ak, sk, region, project_id, sis_config=config) 45 | 46 | # step2 构造请求 47 | asrc_request = AsrCustomLongRequest(obs_audio_format, obs_property, obs_url) 48 | # 所有参数均可不设置,使用默认值 49 | # 设置是否添加标点,yes or no,默认no 50 | asrc_request.set_add_punc('yes') 51 | # 设置是否将语音中数字转写为阿拉伯数字,yes or no,默认yes 52 | asrc_request.set_digit_norm('yes') 53 | # 设置 是否需要分析信息,True or False, 默认False。 只有need_analysis_info生效,diarization、channel、emotion、speed才会生效 54 | # 目前仅支持8k模型,详见api文档 55 | asrc_request.set_need_analysis_info(True) 56 | # 设置是否需要话者分离,默认True,需要need_analysis_info设置为True才生效。 57 | asrc_request.set_diarization(True) 58 | # 设置声道信息, 一般都是单声道,默认为MONO,需要need_analysis_info设置为True才生效 59 | asrc_request.set_channel('MONO') 60 | # 设置是否返回感情信息, 默认True,需要need_analysis_info设置为True才生效。 61 | asrc_request.set_emotion(True) 62 | # 设置是否需要返回语速信息,默认True,需要need_analysis_info设置为True才生效。 63 | asrc_request.set_speed(True) 64 | # 设置回调地址,设置后音频转写结果将直接发送至回调地址。请务必保证地址可联通。 65 | # asrc_request.set_callback_url('') 66 | # 设置是否添加热词表id,没有则不填 67 | # asrc_request.set_vocabulary_id(None) 68 | # 设置是否需要word_info,yes or no, 默认no 69 | asrc_request.set_need_word_info('no') 70 | 71 | # step3 发送请求,获取job_id 72 | job_id = asr_client.submit_job(asrc_request) 73 | 74 | # step4 根据job_id轮询,获取结果。 75 | status = 'WAITING' 76 | count = 0 # 每2s查询一次,尝试2000次,即4000s。如果音频很长,可适当考虑加长一些。 77 | while status != 'FINISHED' and count < 2000: 78 | print(count, ' query') 79 | result = asr_client.get_long_response(job_id) 80 | status = result['status'] 81 | if status == 'ERROR': 82 | print('录音文件识别执行失败, %s' % json.dump(result)) 83 | break 84 | time.sleep(2) 85 | count += 1 86 | if status != 'FINISHED': 87 | print('录音文件识别未在 %d 内获取结果,job_id 为%s' % (count, job_id)) 88 | # result为json格式 89 | print(json.dumps(result, indent=2, ensure_ascii=False)) 90 | 91 | 92 | if __name__ == '__main__': 93 | try: 94 | lasr_example() 95 | except ClientException as e: 96 | print(e) 97 | except ServerException as e: 98 | print(e) -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/pa_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.pa_client import PaClient 4 | from huaweicloud_sis.bean.pa_request import PaAudioRequest 5 | from huaweicloud_sis.bean.pa_request import PaVideoRequest 6 | from huaweicloud_sis.exception.exceptions import ClientException 7 | from huaweicloud_sis.exception.exceptions import ServerException 8 | from huaweicloud_sis.utils import io_utils 9 | from huaweicloud_sis.bean.sis_config import SisConfig 10 | import json 11 | 12 | # 鉴权参数 13 | ak = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 14 | sk = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 15 | region = '' # region,目前仅支持cn-north-4,参考https://support.huaweicloud.com/api-sis/sis_03_0004.html 16 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 17 | 18 | # 语音评测参数, 根据语音和文本对发音进行评分。 19 | audio_path = '' # 音频文件位置, 如D:/test.wav, sdk支持将文件转化为base64编码 20 | audio_ref_text = '' # 音频对应文本,用于评分 21 | 22 | # 多模态评测参数,根据视频和语音及文本,对发音进行评分、 23 | video_path = '' # 视频文件位置, 如D:/test.mp4, sdk支持将文件转化为base64编码 24 | video_ref_text = '' # 视频中音频对应文本,用于评分 25 | 26 | 27 | def assessment_audio_example(): 28 | """ 语音评测示例 """ 29 | # step1 初始化客户端 30 | config = SisConfig() 31 | config.set_connect_timeout(10) # 设置连接超时 32 | config.set_read_timeout(10) # 设置读取超时 33 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 34 | # config.set_proxy(proxy) 35 | pa_client = PaClient(ak, sk, region, project_id, sis_config=config) 36 | 37 | # step2 构造请求 38 | audio_data = io_utils.encode_file(audio_path) 39 | pa_audio_request = PaAudioRequest() 40 | # 设置音频的base64编码 41 | pa_audio_request.set_audio_data(audio_data) 42 | # 设置音频的标准文本 43 | pa_audio_request.set_ref_text(audio_ref_text) 44 | # 设置音频格式,具体支持格式详见api文档。 45 | pa_audio_request.set_audio_format('auto') 46 | # 设置语音,默认en_gb,具体支持详见api文档 47 | pa_audio_request.set_language('en_gb') 48 | # 设置模式,word 或 sentence,默认word,具体支持详见api文档。 49 | pa_audio_request.set_mode('word') 50 | 51 | # step3 发送请求,返回结果,返回结果为json格式 52 | result = pa_client.assessment_audio(pa_audio_request) 53 | print(json.dumps(result, indent=2, ensure_ascii=False)) 54 | 55 | 56 | def assessment_vidoe_example(): 57 | """ 多模态评测示例 """ 58 | # step1 初始化客户端 59 | config = SisConfig() 60 | config.set_connect_timeout(5) # 设置连接超时 61 | config.set_read_timeout(10) # 设置读取超时 62 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 63 | # config.set_proxy(proxy) 64 | pa_client = PaClient(ak, sk, region, project_id, sis_config=config) 65 | 66 | # step2 构造请求 67 | video_data = io_utils.encode_file(video_path) 68 | pa_video_request = PaVideoRequest() 69 | # 设置视频的base64编码 70 | pa_video_request.set_video_data(video_data) 71 | # 设置视频的标准文本 72 | pa_video_request.set_ref_text(video_ref_text) 73 | # 设置视频格式,具体支持格式详见api文档。 74 | pa_video_request.set_video_format('auto') 75 | # 设置语音,默认en_gb,具体支持详见api文档 76 | pa_video_request.set_language('en_gb') 77 | # 设置模式,word 或 sentence,默认word,具体支持详见api文档。 78 | pa_video_request.set_mode('word') 79 | 80 | # step3 发送请求,返回结果,返回结果为json格式 81 | result = pa_client.assessment_video(pa_video_request) 82 | print(json.dumps(result, indent=2, ensure_ascii=False)) 83 | 84 | 85 | if __name__ == '__main__': 86 | try: 87 | assessment_audio_example() # 语音评测 88 | assessment_vidoe_example() # 多模态评测 89 | except ClientException as e: 90 | print(e) 91 | except ServerException as e: 92 | print(e) -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/rasr_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.rasr_client import RasrClient 4 | from huaweicloud_sis.bean.rasr_request import RasrRequest 5 | from huaweicloud_sis.bean.callback import RasrCallBack 6 | from huaweicloud_sis.bean.sis_config import SisConfig 7 | import json 8 | 9 | # 鉴权信息 10 | ak = '' # 用户的ak 11 | sk = '' # 用户的sk 12 | region = 'cn-north-4' # region,如cn-north-4 13 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 14 | 15 | """ 16 | todo 请正确填写音频格式和模型属性字符串 17 | 1. 音频格式一定要相匹配. 18 | 例如音频是pcm格式,并且采样率为8k,则格式填写pcm8k16bit。 19 | 如果返回audio_format is invalid 说明该文件格式不支持。具体支持哪些音频格式,需要参考一些api文档。 20 | 21 | 2. 音频采样率要与属性字符串的采样率要匹配。 22 | 例如格式选择pcm16k16bit,属性字符串却选择chinese_8k_common, 则会返回'audio_format' is not match model 23 | """ 24 | 25 | # 实时语音识别参数 26 | path = '' # 需要发送音频路径,如D:/test.pcm, 同时sdk也支持byte流发送数据。 27 | audio_format = 'pcm16k16bit' # 音频支持格式,如pcm16k16bit,详见api文档 28 | property = 'chinese_16k_general' # 属性字符串,language_sampleRate_domain, 如chinese_16k_general, 采样率要和音频一致。详见api文档 29 | 30 | 31 | class MyCallback(RasrCallBack): 32 | """ 回调类,用户需要在对应方法中实现自己的逻辑,其中on_response必须重写 """ 33 | def on_open(self): 34 | """ websocket连接成功会回调此函数 """ 35 | print('websocket connect success') 36 | 37 | def on_start(self, message): 38 | """ 39 | websocket 开始识别回调此函数 40 | :param message: 传入信息 41 | :return: - 42 | """ 43 | print('webscoket start to recognize, %s' % message) 44 | 45 | def on_response(self, message): 46 | """ 47 | websockert返回响应结果会回调此函数 48 | :param message: json格式 49 | :return: - 50 | """ 51 | print(json.dumps(message, indent=2, ensure_ascii=False)) 52 | 53 | def on_end(self, message): 54 | """ 55 | websocket 结束识别回调此函数 56 | :param message: 传入信息 57 | :return: - 58 | """ 59 | print('websocket is ended, %s' % message) 60 | 61 | def on_close(self): 62 | """ websocket关闭会回调此函数 """ 63 | print('websocket is closed') 64 | 65 | def on_error(self, error): 66 | """ 67 | websocket出错回调此函数 68 | :param error: 错误信息 69 | :return: - 70 | """ 71 | print('websocket meets error, the error is %s' % error) 72 | 73 | def on_event(self, event): 74 | """ 75 | 出现事件的回调 76 | :param event: 事件名称 77 | :return: - 78 | """ 79 | print('receive event %s' % event) 80 | 81 | 82 | def rasr_example(): 83 | """ 实时语音识别demo """ 84 | # step1 初始化RasrClient, 暂不支持使用代理 85 | my_callback = MyCallback() 86 | config = SisConfig() 87 | # 设置连接超时,默认是10 88 | config.set_connect_timeout(10) 89 | # 设置读取超时, 默认是10 90 | config.set_read_timeout(10) 91 | # 设置connect lost超时,一般在普通并发下,不需要设置此值。默认是10 92 | config.set_connect_lost_timeout(10) 93 | # websocket暂时不支持使用代理 94 | rasr_client = RasrClient(ak=ak, sk=sk, use_aksk=True, region=region, project_id=project_id, callback=my_callback, 95 | config=config) 96 | 97 | # step2 构造请求 98 | request = RasrRequest(audio_format, property) 99 | # 所有参数均可不设置,使用默认值 100 | request.set_add_punc('yes') # 设置是否添加标点, yes or no, 默认no 101 | request.set_vad_head(10000) # 设置有效头部, [0, 60000], 默认10000 102 | request.set_vad_tail(500) # 设置有效尾部,[0, 3000], 默认500 103 | request.set_max_seconds(30) # 设置一句话最大长度,[0, 60], 默认30 104 | request.set_interim_results('no') # 设置是否返回中间结果,yes or no,默认no 105 | request.set_digit_norm('no') # 设置是否将语音中数字转写为阿拉伯数字,yes or no,默认yes 106 | # request.set_vocabulary_id('') # 设置热词表id,若不存在则不填写,否则会报错 107 | request.set_need_word_info('no') # 设置是否需要word_info,yes or no, 默认no 108 | 109 | # step3 选择连接模式 110 | # rasr_client.short_stream_connect(request) # 流式一句话模式 111 | # rasr_client.sentence_stream_connect(request) # 实时语音识别单句模式 112 | rasr_client.continue_stream_connect(request) # 实时语音识别连续模式 113 | 114 | # step4 发送音频 115 | rasr_client.send_start() 116 | # 连续模式下,可多次发送音频,发送格式为byte数组 117 | with open(path, 'rb') as f: 118 | data = f.read() 119 | rasr_client.send_audio(data) # 可选byte_len和sleep_time参数,建议使用默认值 120 | rasr_client.send_end() 121 | 122 | # step5 关闭客户端,使用完毕后一定要关闭,否则服务端20s内没收到数据会报错并主动断开。 123 | rasr_client.close() 124 | 125 | 126 | if __name__ == '__main__': 127 | rasr_example() 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/sasr_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.asr_client import AsrCustomizationClient 4 | from huaweicloud_sis.bean.asr_request import AsrCustomShortRequest 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | from huaweicloud_sis.exception.exceptions import ServerException 7 | from huaweicloud_sis.utils import io_utils 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | import json 10 | 11 | # 鉴权参数 12 | ak = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 13 | sk = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 14 | region = '' # region,如cn-north-4 15 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 16 | 17 | """ 18 | todo 请正确填写音频格式和模型属性字符串 19 | 1. 音频格式一定要相匹配. 20 | 例如wav音频,格式是wav。具体参考api文档。 21 | 例如音频是pcm格式,并且采样率为8k,则格式填写pcm8k16bit。 22 | 如果返回audio_format is invalid 说明该文件格式不支持。具体支持哪些音频格式,需要参考一些api文档。 23 | 24 | 2. 音频采样率要与属性字符串的采样率要匹配。 25 | 例如格式选择pcm16k16bit,属性字符串却选择chinese_8k_common, 则会返回'audio_format' is not match model 26 | 例如wav本身是16k采样率,属性选择chinese_8k_common, 同样会返回'audio_format' is not match model 27 | """ 28 | 29 | # 一句话识别参数,以音频文件的base64编码传入,1min以内音频 30 | path = '' # 文件位置, 需要具体到文件,如D:/test.wav 31 | path_audio_format = '' # 音频格式,如wav等,详见api文档 32 | path_property = '' # language_sampleRate_domain, 如chinese_8k_common,详见api文档 33 | 34 | 35 | def sasr_example(): 36 | """ 一句话识别示例 """ 37 | # step1 初始化客户端 38 | config = SisConfig() 39 | config.set_connect_timeout(10) # 设置连接超时 40 | config.set_read_timeout(10) # 设置读取超时 41 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 42 | # config.set_proxy(proxy) 43 | asr_client = AsrCustomizationClient(ak, sk, region, project_id, sis_config=config) 44 | 45 | # step2 构造请求 46 | data = io_utils.encode_file(path) 47 | asr_request = AsrCustomShortRequest(path_audio_format, path_property, data) 48 | # 所有参数均可不设置,使用默认值 49 | # 设置是否添加标点,yes or no,默认no 50 | asr_request.set_add_punc('yes') 51 | # 设置是否将语音中数字转写为阿拉伯数字,yes or no,默认yes 52 | asr_request.set_digit_norm('yes') 53 | # 设置是否添加热词表id,没有则不填 54 | # asr_request.set_vocabulary_id(None) 55 | # 设置是否需要word_info,yes or no, 默认no 56 | asr_request.set_need_word_info('no') 57 | 58 | # step3 发送请求,返回结果,返回结果为json格式 59 | result = asr_client.get_short_response(asr_request) 60 | print(json.dumps(result, indent=2, ensure_ascii=False)) 61 | 62 | 63 | if __name__ == '__main__': 64 | try: 65 | sasr_example() 66 | except ClientException as e: 67 | print(e) 68 | except ServerException as e: 69 | print(e) 70 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/sasr_websocket_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.asr_client import SasrWebsocketClient 4 | from huaweicloud_sis.bean.asr_request import SasrWebsocketRequest 5 | from huaweicloud_sis.bean.callback import RasrCallBack 6 | from huaweicloud_sis.bean.sis_config import SisConfig 7 | import json 8 | 9 | # 鉴权信息 10 | ak = '' # 用户的ak 11 | sk = '' # 用户的sk 12 | region = 'cn-north-4' # region,如cn-north-4 13 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 14 | 15 | # 一句话识别参数 16 | path = '' # 需要发送音频路径,如D:/test.pcm, 同时sdk也支持byte流发送数据。 17 | audio_format = '' # 音频支持格式,如pcm16k16bit,详见api文档 18 | property = '' # 属性字符串,language_sampleRate_domain, 如chinese_16k_common, 采样率要和音频一致。详见api文档 19 | 20 | 21 | class MyCallback(RasrCallBack): 22 | """ 回调类,用户需要在对应方法中实现自己的逻辑,其中on_response必须重写 """ 23 | 24 | def on_open(self): 25 | """ websocket连接成功会回调此函数 """ 26 | print('websocket connect success') 27 | 28 | def on_start(self, message): 29 | """ 30 | websocket 开始识别回调此函数 31 | :param message: 传入信息 32 | :return: - 33 | """ 34 | print('webscoket start to recognize, %s' % message) 35 | 36 | def on_response(self, message): 37 | """ 38 | websockert返回响应结果会回调此函数 39 | :param message: json格式 40 | :return: - 41 | """ 42 | print(json.dumps(message, indent=2, ensure_ascii=False)) 43 | 44 | def on_end(self, message): 45 | """ 46 | websocket 结束识别回调此函数 47 | :param message: 传入信息 48 | :return: - 49 | """ 50 | print('websocket is ended, %s' % message) 51 | 52 | def on_close(self): 53 | """ websocket关闭会回调此函数 """ 54 | print('websocket is closed') 55 | 56 | def on_error(self, error): 57 | """ 58 | websocket出错回调此函数 59 | :param error: 错误信息 60 | :return: - 61 | """ 62 | print('websocket meets error, the error is %s' % error) 63 | 64 | def on_event(self, event): 65 | """ 66 | 出现事件的回调 67 | :param event: 事件名称 68 | :return: - 69 | """ 70 | print('receive event %s' % event) 71 | 72 | 73 | def sasr_websocket_example(): 74 | """ 一句话识别 websocket demo """ 75 | # step1 初始化SasrWebsocketClient, 暂不支持使用代理 76 | my_callback = MyCallback() 77 | config = SisConfig() 78 | # 设置连接超时,默认是10 79 | config.set_connect_timeout(10) 80 | # 设置读取超时, 默认是10 81 | config.set_read_timeout(10) 82 | # 设置connect lost超时,一般在普通并发下,不需要设置此值。默认是10 83 | config.set_connect_lost_timeout(10) 84 | # websocket暂时不支持使用代理 85 | sasr_websocket_client = SasrWebsocketClient(ak=ak, sk=sk, use_aksk=True, region=region, project_id=project_id, 86 | callback=my_callback, config=config) 87 | 88 | # step2 构造请求 89 | request = SasrWebsocketRequest(audio_format, property) 90 | # 所有参数均可不设置,使用默认值 91 | request.set_add_punc('yes') # 设置是否添加标点, yes or no, 默认no 92 | request.set_interim_results('no') # 设置是否返回中间结果,yes or no,默认no 93 | request.set_digit_norm('no') # 设置是否将语音中数字转写为阿拉伯数字,yes or no,默认yes 94 | # request.set_vocabulary_id('') # 设置热词表id,若不存在则不填写,否则会报错 95 | request.set_need_word_info('no') # 设置是否需要word_info,yes or no, 默认no 96 | 97 | # step3 连接服务端 98 | sasr_websocket_client.sasr_stream_connect(request) 99 | 100 | # step4 发送音频 101 | sasr_websocket_client.send_start() 102 | # 连续模式下,可多次发送音频,发送格式为byte数组 103 | with open(path, 'rb') as f: 104 | data = f.read() 105 | sasr_websocket_client.send_audio(data) # 可选byte_len和sleep_time参数,建议使用默认值 106 | sasr_websocket_client.send_end() 107 | 108 | # step5 关闭客户端,使用完毕后一定要关闭,否则服务端20s内没收到数据会报错并主动断开。 109 | sasr_websocket_client.close() 110 | 111 | 112 | if __name__ == '__main__': 113 | sasr_websocket_example() 114 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/cn_demo/tts_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.tts_client import TtsCustomizationClient 4 | from huaweicloud_sis.bean.tts_request import TtsCustomRequest 5 | from huaweicloud_sis.bean.sis_config import SisConfig 6 | from huaweicloud_sis.exception.exceptions import ClientException 7 | from huaweicloud_sis.exception.exceptions import ServerException 8 | import json 9 | 10 | 11 | def ttsc_example(): 12 | """ 语音合成demo """ 13 | ak = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 14 | sk = '' # 参考https://support.huaweicloud.com/sdkreference-sis/sis_05_0003.html 15 | region = '' # region,如cn-north-4 16 | project_id = '' # 同region一一对应,参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 17 | text = '' # 待合成文本,不超过500字 18 | path = '' # 保存路径,如D:/test.wav。 可在设置中选择不保存本地 19 | 20 | # step1 初始化客户端 21 | config = SisConfig() 22 | config.set_connect_timeout(10) # 设置连接超时,单位s 23 | config.set_read_timeout(10) # 设置读取超时,单位s 24 | # 设置代理,使用代理前一定要确保代理可用。 代理格式可为[host, port] 或 [host, port, username, password] 25 | # config.set_proxy(proxy) 26 | ttsc_client = TtsCustomizationClient(ak, sk, region, project_id, sis_config=config) 27 | 28 | # step2 构造请求 29 | ttsc_request = TtsCustomRequest(text) 30 | # 设置请求,所有参数均可不设置,使用默认参数 31 | # 设置属性字符串, language_speaker_domain, 默认chinese_xiaoyan_common, 参考api文档 32 | ttsc_request.set_property('chinese_xiaoyan_common') 33 | # 设置音频格式,默认wav,可选mp3和pcm 34 | ttsc_request.set_audio_format('wav') 35 | # 设置采样率,8000 or 16000, 默认8000 36 | ttsc_request.set_sample_rate('8000') 37 | # 设置音量,[0, 100],默认50 38 | ttsc_request.set_volume(50) 39 | # 设置音高, [-500, 500], 默认0 40 | ttsc_request.set_pitch(0) 41 | # 设置音速, [-500, 500], 默认0 42 | ttsc_request.set_speed(0) 43 | # 设置是否保存,默认False 44 | ttsc_request.set_saved(True) 45 | # 设置保存路径,只有设置保存,此参数才生效 46 | ttsc_request.set_saved_path(path) 47 | 48 | # step3 发送请求,返回结果。如果设置保存,可在指定路径里查看保存的音频。 49 | result = ttsc_client.get_ttsc_response(ttsc_request) 50 | print(json.dumps(result, indent=2, ensure_ascii=False)) 51 | 52 | 53 | if __name__ == '__main__': 54 | try: 55 | ttsc_example() 56 | except ClientException as e: 57 | print(e) 58 | except ServerException as e: 59 | print(e) 60 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/16k.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/16k.pcm -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/16k.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/16k.wav -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/8k.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/8k.pcm -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/8k.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/chinese/8k.wav -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/16k.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/16k.pcm -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/16k.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/16k.wav -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/8k.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/8k.pcm -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/8k.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/data/english/8k.wav -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/dist/huaweicloud_python_sdk_sis-1.7.1-py3.8.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/dist/huaweicloud_python_sdk_sis-1.7.1-py3.8.egg -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_python_sdk_sis.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: huaweicloud-python-sdk-sis 3 | Version: 1.7.1 4 | Summary: sis python sdk 5 | Author: Huaweicloud SIS 6 | License: Apache-2.0 7 | Keywords: sis,sdk,python 8 | Platform: Independant 9 | 10 | sis python sdk 11 | 12 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_python_sdk_sis.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | setup.py 2 | huaweicloud_python_sdk_sis.egg-info/PKG-INFO 3 | huaweicloud_python_sdk_sis.egg-info/SOURCES.txt 4 | huaweicloud_python_sdk_sis.egg-info/dependency_links.txt 5 | huaweicloud_python_sdk_sis.egg-info/not-zip-safe 6 | huaweicloud_python_sdk_sis.egg-info/requires.txt 7 | huaweicloud_python_sdk_sis.egg-info/top_level.txt 8 | huaweicloud_sis/__init__.py 9 | huaweicloud_sis/auth/__init__.py 10 | huaweicloud_sis/auth/aksk_service.py 11 | huaweicloud_sis/auth/signer.py 12 | huaweicloud_sis/auth/token_service.py 13 | huaweicloud_sis/bean/__init__.py 14 | huaweicloud_sis/bean/asr_request.py 15 | huaweicloud_sis/bean/callback.py 16 | huaweicloud_sis/bean/flash_lasr_request.py 17 | huaweicloud_sis/bean/hot_word_request.py 18 | huaweicloud_sis/bean/pa_request.py 19 | huaweicloud_sis/bean/rasr_request.py 20 | huaweicloud_sis/bean/rtts_request.py 21 | huaweicloud_sis/bean/sis_config.py 22 | huaweicloud_sis/bean/tts_request.py 23 | huaweicloud_sis/client/__init__.py 24 | huaweicloud_sis/client/asr_client.py 25 | huaweicloud_sis/client/flash_lasr_client.py 26 | huaweicloud_sis/client/hot_word_client.py 27 | huaweicloud_sis/client/pa_client.py 28 | huaweicloud_sis/client/rasr_client.py 29 | huaweicloud_sis/client/rtts_client.py 30 | huaweicloud_sis/client/tts_client.py 31 | huaweicloud_sis/exception/__init__.py 32 | huaweicloud_sis/exception/exceptions.py 33 | huaweicloud_sis/utils/__init__.py 34 | huaweicloud_sis/utils/http_utils.py 35 | huaweicloud_sis/utils/io_utils.py 36 | huaweicloud_sis/utils/logger_utils.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_python_sdk_sis.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_python_sdk_sis.egg-info/not-zip-safe: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_python_sdk_sis.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | websocket-client 2 | requests 3 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_python_sdk_sis.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | huaweicloud_sis 2 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/auth/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/auth/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/auth/aksk_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import json 4 | from huaweicloud_sis.auth import signer 5 | from huaweicloud_sis.bean.sis_config import SisConfig 6 | from huaweicloud_sis.utils import http_utils 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.utils.logger_utils import logger 9 | 10 | 11 | def get_signed_headers(ak, sk, url, headers, params, http_method): 12 | """ 13 | 根据ak和sk以及请求信息获取加密头部 14 | @:return 加密的头部 15 | """ 16 | sig = signer.Signer() 17 | sig.Key = ak 18 | sig.Secret = sk 19 | if params is None: 20 | body = '' 21 | else: 22 | body = params 23 | if isinstance(params, dict): 24 | body = json.dumps(params) 25 | r = signer.HttpRequest(http_method, url, headers, body) 26 | sig.Sign(r) 27 | return r.headers 28 | 29 | 30 | def aksk_connect(ak, sk, url, headers, params, http_method, config=None): 31 | """ 32 | 根据url,返回json 33 | :param ak: ak 34 | :param sk: sk 35 | :param url: 完整请求url 36 | :param headers: 请求header,dict 37 | :param params: 请求参数, dict 38 | :param http_method: 请求方法,'POST' or 'GET', 其他会报错 39 | :param config: SisConfig(), 配置超时和代理 40 | :return: http返回结果转化为json 41 | """ 42 | sis_config = config 43 | if sis_config is None: 44 | sis_config = SisConfig() 45 | if not isinstance(sis_config, SisConfig): 46 | error_msg = 'the param \'config\' in aksk_connect must be SisConfig class' 47 | logger.error(error_msg) 48 | raise ClientException(error_msg) 49 | signed_headers = get_signed_headers(ak, sk, url, headers, params, http_method) 50 | time_out = (sis_config.get_connect_timeout(), sis_config.get_read_timeout()) 51 | resp = http_utils.http_connect(url, signed_headers, params, http_method, time_out, sis_config.get_proxy(), 52 | sis_config.get_certificate_check()) 53 | json_result = http_utils.parse_resp(resp) 54 | if resp is not None: 55 | resp.close() 56 | return json_result 57 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/auth/signer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import copy 4 | import sys 5 | import hashlib 6 | import hmac 7 | import binascii 8 | from datetime import datetime 9 | 10 | if sys.version_info.major < 3: 11 | from urllib import quote, unquote 12 | 13 | 14 | def hmacsha256(keyByte, message): 15 | return hmac.new(keyByte, message, digestmod=hashlib.sha256).digest() 16 | 17 | 18 | # Create a "String to Sign". 19 | def StringToSign(canonicalRequest, t): 20 | bytes = HexEncodeSHA256Hash(canonicalRequest) 21 | return "%s\n%s\n%s" % (Algorithm, datetime.strftime(t, BasicDateFormat), bytes) 22 | 23 | else: 24 | from urllib.parse import quote, unquote 25 | 26 | 27 | def hmacsha256(keyByte, message): 28 | return hmac.new(keyByte.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).digest() 29 | 30 | 31 | # Create a "String to Sign". 32 | def StringToSign(canonicalRequest, t): 33 | bytes = HexEncodeSHA256Hash(canonicalRequest.encode('utf-8')) 34 | return "%s\n%s\n%s" % (Algorithm, datetime.strftime(t, BasicDateFormat), bytes) 35 | 36 | 37 | def urlencode(s): 38 | return quote(s, safe='~') 39 | 40 | 41 | def findHeader(r, header): 42 | for k in r.headers: 43 | if k.lower() == header.lower(): 44 | return r.headers[k] 45 | return None 46 | 47 | 48 | # HexEncodeSHA256Hash returns hexcode of sha256 49 | def HexEncodeSHA256Hash(data): 50 | sha256 = hashlib.sha256() 51 | sha256.update(data) 52 | return sha256.hexdigest() 53 | 54 | 55 | # HWS API Gateway Signature 56 | class HttpRequest: 57 | def __init__(self, method="", url="", headers=None, body=""): 58 | self.method = method 59 | spl = url.split("://", 1) 60 | scheme = 'http' 61 | if len(spl) > 1: 62 | scheme = spl[0] 63 | url = spl[1] 64 | query = {} 65 | spl = url.split('?', 1) 66 | url = spl[0] 67 | if len(spl) > 1: 68 | for kv in spl[1].split("&"): 69 | spl = kv.split("=", 1) 70 | key = spl[0] 71 | value = "" 72 | if len(spl) > 1: 73 | value = spl[1] 74 | if key != '': 75 | key = unquote(key) 76 | value = unquote(value) 77 | if key in query: 78 | query[key].append(value) 79 | else: 80 | query[key] = [value] 81 | spl = url.split('/', 1) 82 | host = spl[0] 83 | if len(spl) > 1: 84 | url = '/' + spl[1] 85 | else: 86 | url = '/' 87 | 88 | self.scheme = scheme 89 | self.host = host 90 | self.uri = url 91 | self.query = query 92 | if headers is None: 93 | self.headers = {} 94 | else: 95 | self.headers = copy.deepcopy(headers) 96 | if sys.version_info.major < 3: 97 | self.body = body 98 | else: 99 | self.body = body.encode("utf-8") 100 | 101 | 102 | BasicDateFormat = "%Y%m%dT%H%M%SZ" 103 | Algorithm = "SDK-HMAC-SHA256" 104 | HeaderXDate = "X-Sdk-Date" 105 | HeaderHost = "host" 106 | HeaderAuthorization = "Authorization" 107 | HeaderContentSha256 = "x-sdk-content-sha256" 108 | 109 | 110 | # Build a CanonicalRequest from a regular request string 111 | # 112 | # CanonicalRequest = 113 | # HTTPRequestMethod + '\n' + 114 | # CanonicalURI + '\n' + 115 | # CanonicalQueryString + '\n' + 116 | # CanonicalHeaders + '\n' + 117 | # SignedHeaders + '\n' + 118 | # HexEncode(Hash(RequestPayload)) 119 | def CanonicalRequest(r, signedHeaders): 120 | canonicalHeaders = CanonicalHeaders(r, signedHeaders) 121 | hexencode = findHeader(r, HeaderContentSha256) 122 | if hexencode is None: 123 | hexencode = HexEncodeSHA256Hash(r.body) 124 | return "%s\n%s\n%s\n%s\n%s\n%s" % (r.method.upper(), CanonicalURI(r), CanonicalQueryString(r), 125 | canonicalHeaders, ";".join(signedHeaders), hexencode) 126 | 127 | 128 | def CanonicalURI(r): 129 | pattens = unquote(r.uri).split('/') 130 | uri = [] 131 | for v in pattens: 132 | uri.append(urlencode(v)) 133 | urlpath = "/".join(uri) 134 | if urlpath[-1] != '/': 135 | urlpath = urlpath + "/" # always end with / 136 | # r.uri = urlpath 137 | return urlpath 138 | 139 | 140 | def CanonicalQueryString(r): 141 | keys = [] 142 | for key in r.query: 143 | keys.append(key) 144 | keys.sort() 145 | a = [] 146 | for key in keys: 147 | k = urlencode(key) 148 | value = r.query[key] 149 | if type(value) is list: 150 | value.sort() 151 | for v in value: 152 | kv = k + "=" + urlencode(str(v)) 153 | a.append(kv) 154 | else: 155 | kv = k + "=" + urlencode(str(value)) 156 | a.append(kv) 157 | return '&'.join(a) 158 | 159 | 160 | def CanonicalHeaders(r, signedHeaders): 161 | a = [] 162 | __headers = {} 163 | for key in r.headers: 164 | keyEncoded = key.lower() 165 | value = r.headers[key] 166 | valueEncoded = value.strip() 167 | __headers[keyEncoded] = valueEncoded 168 | if sys.version_info.major == 3: 169 | r.headers[key] = valueEncoded.encode("utf-8").decode('iso-8859-1') 170 | for key in signedHeaders: 171 | a.append(key + ":" + __headers[key]) 172 | return '\n'.join(a) + "\n" 173 | 174 | 175 | def SignedHeaders(r): 176 | a = [] 177 | for key in r.headers: 178 | a.append(key.lower()) 179 | a.sort() 180 | return a 181 | 182 | 183 | # Create the HWS Signature. 184 | def SignStringToSign(stringToSign, signingKey): 185 | hm = hmacsha256(signingKey, stringToSign) 186 | return binascii.hexlify(hm).decode() 187 | 188 | 189 | # Get the finalized value for the "Authorization" header. The signature 190 | # parameter is the output from SignStringToSign 191 | def AuthHeaderValue(signature, AppKey, signedHeaders): 192 | return "%s Access=%s, SignedHeaders=%s, Signature=%s" % ( 193 | Algorithm, AppKey, ";".join(signedHeaders), signature) 194 | 195 | 196 | class Signer: 197 | def __init__(self): 198 | self.Key = "" 199 | self.Secret = "" 200 | 201 | def Verify(self, r, authorization): 202 | if sys.version_info.major == 3 and isinstance(r.body, str): 203 | r.body = r.body.encode('utf-8') 204 | headerTime = findHeader(r, HeaderXDate) 205 | if headerTime is None: 206 | return False 207 | else: 208 | t = datetime.strptime(headerTime, BasicDateFormat) 209 | 210 | signedHeaders = SignedHeaders(r) 211 | canonicalRequest = CanonicalRequest(r, signedHeaders) 212 | stringToSign = StringToSign(canonicalRequest, t) 213 | return authorization == SignStringToSign(stringToSign, self.Secret) 214 | 215 | # SignRequest set Authorization header 216 | def Sign(self, r): 217 | if sys.version_info.major == 3 and isinstance(r.body, str): 218 | r.body = r.body.encode('utf-8') 219 | headerTime = findHeader(r, HeaderXDate) 220 | if headerTime is None: 221 | t = datetime.utcnow() 222 | r.headers[HeaderXDate] = datetime.strftime(t, BasicDateFormat) 223 | else: 224 | t = datetime.strptime(headerTime, BasicDateFormat) 225 | 226 | haveHost = False 227 | for key in r.headers: 228 | if key.lower() == 'host': 229 | haveHost = True 230 | break 231 | if not haveHost: 232 | r.headers["host"] = r.host 233 | signedHeaders = SignedHeaders(r) 234 | canonicalRequest = CanonicalRequest(r, signedHeaders) 235 | stringToSign = StringToSign(canonicalRequest, t) 236 | signature = SignStringToSign(stringToSign, self.Secret) 237 | authValue = AuthHeaderValue(signature, self.Key, signedHeaders) 238 | r.headers[HeaderAuthorization] = authValue 239 | r.headers["content-length"] = str(len(r.body)) 240 | queryString = CanonicalQueryString(r) 241 | if queryString != "": 242 | r.uri = r.uri + "?" + queryString 243 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/auth/token_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.utils import http_utils 4 | from huaweicloud_sis.bean.sis_config import SisConfig 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | from huaweicloud_sis.utils.logger_utils import logger 7 | 8 | 9 | def get_token(user_name, password, domain_name, region, url=None, config=SisConfig()): 10 | """ 11 | 获取token 12 | :param user_name: 用户名 13 | :param password: 密码 14 | :param domain_name: 账户名,一般等同用户名 15 | :param region: 区域,如cn-north-4 16 | :param url: 请求token的url,可使用默认值 17 | :param config 配置信息 18 | :return: 请求的token 19 | """ 20 | if url is None: 21 | url = 'https://iam.' + region + '.myhuaweicloud.com/v3/auth/tokens' 22 | if not isinstance(config, SisConfig): 23 | error_msg = 'the param \'config\' in token_service must be SisConfig class' 24 | logger.error(error_msg) 25 | raise ClientException(error_msg) 26 | time_out = (config.get_connect_timeout(), config.get_read_timeout()) 27 | proxy = config.get_proxy() 28 | auth_data = { 29 | "auth": { 30 | "identity": { 31 | "password": { 32 | "user": { 33 | "name": user_name, 34 | "password": password, 35 | "domain": { 36 | "name": domain_name 37 | } 38 | } 39 | }, 40 | "methods": [ 41 | "password" 42 | ] 43 | }, 44 | "scope": { 45 | "project": { 46 | "name": region 47 | } 48 | } 49 | } 50 | } 51 | 52 | headers = {'Content-Type': 'application/json'} 53 | req = http_utils.http_connect(url, headers, auth_data, 'POST', time_out, proxy, config.get_certificate_check()) 54 | if 'X-Subject-Token' not in req.headers: 55 | logger.error('Error occurs in getting token, %s' % req.text) 56 | raise ClientException('Error occurs in getting token, %s' % req.text) 57 | token = req.headers['X-Subject-Token'] 58 | return token 59 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/asr_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from huaweicloud_sis.bean.rasr_request import RasrRequest 3 | 4 | class AsrCustomShortRequest: 5 | """ 一句话识别请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | def __init__(self, audio_format, model_property, data): 7 | """ 8 | 一句话识别请求初始化 9 | :param audio_format: 音频格式,详见api文档 10 | :param model_property: language_sampleRate_domain, 如chinese_8k_common, 详见api文档 11 | :param data: 音频转化后的base64字符串 12 | """ 13 | self._audio_format = audio_format 14 | self._property = model_property 15 | self._data = data 16 | self._add_punc = 'no' 17 | self._digit_norm = 'yes' 18 | self._vocabulary_id = None 19 | self._need_word_info = 'no' 20 | self._user_words = list() 21 | 22 | def set_add_punc(self, add_punc): 23 | self._add_punc = add_punc 24 | 25 | def set_digit_norm(self, digit_norm): 26 | self._digit_norm = digit_norm 27 | 28 | def set_vocabulary_id(self, vocabulary_id): 29 | self._vocabulary_id = vocabulary_id 30 | 31 | def set_need_word_info(self, need_word_info): 32 | self._need_word_info = need_word_info 33 | 34 | def set_user_words(self, user_words): 35 | self._user_words = user_words 36 | 37 | def construct_params(self): 38 | params = dict() 39 | params['data'] = self._data 40 | config = dict() 41 | config['audio_format'] = self._audio_format 42 | config['property'] = self._property 43 | config['add_punc'] = self._add_punc 44 | config['digit_norm'] = self._digit_norm 45 | config['need_word_info'] = self._need_word_info 46 | if self._vocabulary_id is not None: 47 | config['vocabulary_id'] = self._vocabulary_id 48 | if self._user_words is not None and len(self._user_words) > 0: 49 | config['user_words'] = self._user_words 50 | params['config'] = config 51 | return params 52 | 53 | 54 | class AsrCustomLongRequest: 55 | """ 录音文件识别请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 56 | def __init__(self, audio_format, model_property, data_url): 57 | """ 58 | 录音文件识别初始化 59 | :param audio_format: 音频格式,详见api文档 60 | :param model_property: 属性字符串,language_sampleRate_domain, 详见api文档 61 | :param data_url: 音频的obs链接 62 | """ 63 | self._audio_format = audio_format 64 | self._property = model_property 65 | self._data_url = data_url 66 | self._add_punc = 'no' 67 | self._digit_norm = 'yes' 68 | self._callback_url = None 69 | self._need_analysis_info = False 70 | self._diarization = True 71 | self._channel = 'MONO' 72 | self._emotion = True 73 | self._speed = True 74 | self._vocabulary_id = None 75 | self._need_word_info = 'no' 76 | 77 | def set_callback_url(self, callback_url): 78 | self._callback_url = callback_url 79 | 80 | def set_add_punc(self, add_punc): 81 | self._add_punc = add_punc 82 | 83 | def set_digit_norm(self, digit_norm): 84 | self._digit_norm = digit_norm 85 | 86 | def set_need_analysis_info(self, need_analysis_info): 87 | self._need_analysis_info = need_analysis_info 88 | 89 | def set_diarization(self, diarization): 90 | self._diarization = diarization 91 | 92 | def set_channel(self, channel): 93 | self._channel = channel 94 | 95 | def set_emotion(self, emotion): 96 | self._emotion = emotion 97 | 98 | def set_speed(self, speed): 99 | self._speed = speed 100 | 101 | def set_vocabulary_id(self, vocabulary_id): 102 | self._vocabulary_id = vocabulary_id 103 | 104 | def set_need_word_info(self, need_word_info): 105 | self._need_word_info = need_word_info 106 | 107 | def construct_parameter(self): 108 | params = dict() 109 | params['data_url'] = self._data_url 110 | config = dict() 111 | config['audio_format'] = self._audio_format 112 | config['property'] = self._property 113 | config['add_punc'] = self._add_punc 114 | config['digit_norm'] = self._digit_norm 115 | config['need_word_info'] = self._need_word_info 116 | if self._callback_url is not None and not self._callback_url == '': 117 | config['callback_url'] = self._callback_url 118 | if self._need_analysis_info: 119 | need_analysis_info = dict() 120 | need_analysis_info['diarization'] = self._diarization 121 | need_analysis_info['channel'] = self._channel 122 | need_analysis_info['emotion'] = self._emotion 123 | need_analysis_info['speed'] = self._speed 124 | config['need_analysis_info'] = need_analysis_info 125 | if self._vocabulary_id is not None: 126 | config['vocabulary_id'] = self._vocabulary_id 127 | params['config'] = config 128 | return params 129 | 130 | 131 | class SasrWebsocketRequest(RasrRequest): 132 | def __init__(self, audio_format, model_property): 133 | super().__init__(audio_format, model_property) 134 | 135 | def construct_params(self): 136 | result = super().construct_params() 137 | remove_list = ['vad_head', 'vad_tail', 'max_seconds'] 138 | for key in remove_list: 139 | if key in result: 140 | del result[key] 141 | return result 142 | 143 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/callback.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # -*- coding: utf-8 -*- 3 | 4 | from huaweicloud_sis.utils.logger_utils import logger 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | 7 | 8 | class RasrCallBack: 9 | """ 实时语音识别的监听接口,监听创立链接、开始、中间响应、结束、关闭连接、错误 """ 10 | def on_open(self): 11 | logger.debug('websocket connect success') 12 | 13 | def on_start(self, message): 14 | logger.debug('websocket start, %s' % message) 15 | 16 | def on_response(self, message): 17 | raise ClientException('no response implementation') 18 | 19 | def on_end(self, message): 20 | logger.debug('websocket end, %s' % message) 21 | 22 | def on_close(self): 23 | logger.debug('websocket close') 24 | 25 | def on_error(self, error): 26 | logger.error(error) 27 | 28 | def on_event(self, event): 29 | logger.info("receive event %s" % event) 30 | 31 | 32 | class RttsCallBack: 33 | def on_close(self): 34 | logger.debug('websocket close') 35 | 36 | def on_open(self): 37 | logger.debug('websocket connect success') 38 | 39 | def on_start(self, message): 40 | logger.debug('websocket start, %s' % message) 41 | 42 | def on_response(self, data): 43 | raise ClientException('no response implementation') 44 | 45 | def on_end(self, message): 46 | logger.debug('websocket end, %s' % message) 47 | 48 | def on_error(self, error): 49 | logger.error(error) 50 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/flash_lasr_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | class FlashLasrRequest: 4 | def __init__(self): 5 | self._audio_format = None 6 | self._property = None 7 | self._add_punc = 'no' 8 | self._digit_norm = 'no' 9 | self._vocabulary_id = None 10 | self._need_word_info = 'no' 11 | self._first_channel_only = 'no' 12 | self._obs_bucket_name = None 13 | self._obs_object_key = None 14 | 15 | def set_audio_format(self, audio_format): 16 | self._audio_format = audio_format 17 | 18 | def set_property(self, property): 19 | self._property = property 20 | 21 | def set_add_punc(self, add_punc): 22 | self._add_punc = add_punc 23 | 24 | def set_digit_norm(self, digit_norm): 25 | self._digit_norm = digit_norm 26 | 27 | def set_vocabulary_id(self, vocabulary_id): 28 | self._vocabulary_id = vocabulary_id 29 | 30 | def set_need_word_info(self, need_word_info): 31 | self._need_word_info = need_word_info 32 | 33 | def set_first_channel_only(self, first_channel_only): 34 | self._first_channel_only = first_channel_only 35 | 36 | def set_obs_bucket_name(self, obs_bucket_name): 37 | self._obs_bucket_name = obs_bucket_name 38 | 39 | def set_obs_object_key(self, obs_object_key): 40 | self._obs_object_key = obs_object_key 41 | 42 | def construct_params(self): 43 | params = '?' 44 | if self._audio_format is not None: 45 | params += '&audio_format=' + str(self._audio_format) 46 | if self._property is not None: 47 | params += '&property=' + str(self._property) 48 | params += '&add_punc=' + str(self._add_punc) 49 | params += '&digit_norm=' + str(self._digit_norm) 50 | 51 | if self._vocabulary_id is not None: 52 | params += '&vocabulary_id=' + str(self._vocabulary_id) 53 | params += '&need_word_info=' + str(self._need_word_info) 54 | params += '&first_channel_only=' + str(self._first_channel_only) 55 | if self._obs_bucket_name is not None: 56 | params += '&obs_bucket_name=' + str(self._obs_bucket_name) 57 | if self._obs_object_key is not None: 58 | params += '&obs_object_key=' + str(self._obs_object_key) 59 | return params 60 | 61 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/hot_word_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class HotWordRequest: 5 | def __init__(self, name, word_list): 6 | self._name = name 7 | self._word_list = word_list 8 | self._language = 'chinese_mandarin' 9 | self._description = '' 10 | 11 | def set_description(self, description): 12 | self._description = description 13 | 14 | def set_language(self, language): 15 | self._language = language 16 | 17 | def construct_params(self): 18 | params_dict = { 19 | 'name': self._name, 20 | 'language': self._language, 21 | 'description': self._description, 22 | 'contents': self._word_list 23 | } 24 | return params_dict 25 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/pa_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.utils.logger_utils import logger 4 | from huaweicloud_sis.exception.exceptions import ClientException 5 | 6 | 7 | class PaAudioRequest: 8 | """ 语音评测请求 """ 9 | def __init__(self): 10 | """ 11 | 语音请求初始化 12 | """ 13 | self._audio_data = None 14 | self._audio_url = None 15 | self._ref_text = None 16 | self._audio_format = 'auto' 17 | self._language = 'en_gb' 18 | self._mode = 'word' 19 | 20 | def set_audio_data(self, audio_data): 21 | self._audio_data = audio_data 22 | 23 | def set_audio_url(self, audio_url): 24 | self._audio_url = audio_url 25 | 26 | def set_audio_format(self, audio_format): 27 | self._audio_format = audio_format 28 | 29 | def set_ref_text(self, ref_text): 30 | self._ref_text = ref_text 31 | 32 | def set_language(self, language): 33 | self._language = language 34 | 35 | def set_mode(self, mode): 36 | self._mode = mode 37 | 38 | def construct_params(self): 39 | if self._audio_data is None and self._audio_url is None: 40 | logger.error('In PaAudioRequest, audio_data and audio_url can\'t be both empty') 41 | raise ClientException('In PaAudioRequest, audio_data and audio_url can\'t be both empty') 42 | if self._ref_text is None: 43 | logger.error('In PaAudioRequest, ref_text can\'t be empty') 44 | raise ClientException('In PaAudioRequest, ref_text can\'t be empty') 45 | if self._audio_data is not None and self._audio_url is not None: 46 | logger.warn('When audio_data and audio_url are all filled, only audio_data takes effect') 47 | params_dict = { 48 | 'ref_text': self._ref_text, 49 | 'config': { 50 | 'audio_format': self._audio_format, 51 | 'language': self._language, 52 | 'mode': self._mode 53 | } 54 | } 55 | if self._audio_data is not None: 56 | params_dict['audio_data'] = self._audio_data 57 | else: 58 | params_dict['audio_url'] = self._audio_url 59 | return params_dict 60 | 61 | 62 | class PaVideoRequest: 63 | def __init__(self): 64 | """ 65 | 多模态评测请求 66 | 67 | """ 68 | self._video_data = None 69 | self._video_url = None 70 | self._video_format = 'auto' 71 | self._ref_text = None 72 | self._language = 'en_gb' 73 | self._mode = 'word' 74 | 75 | def set_video_data(self, video_data): 76 | self._video_data = video_data 77 | 78 | def set_video_url(self, video_url): 79 | self._video_url = video_url 80 | 81 | def set_video_format(self, video_format): 82 | self._video_format = video_format 83 | 84 | def set_ref_text(self, ref_text): 85 | self._ref_text = ref_text 86 | 87 | def set_language(self, language): 88 | self._language = language 89 | 90 | def set_mode(self, mode): 91 | self._mode = mode 92 | 93 | def construct_parameter(self): 94 | if self._video_data is None and self._video_url is None: 95 | logger.error('In PaVideoRequest, video_data and video_url can\'t be both empty') 96 | raise ClientException('In PaVideoRequest, video_data and video_url can\'t be both empty') 97 | if self._ref_text is None: 98 | logger.error('In PaVideoRequest, ref_text can\'t be empty') 99 | raise ClientException('In PaVideoRequest, ref_text can\'t be empty') 100 | if self._video_data is not None and self._video_url is not None: 101 | logger.warn('When video_data and video_url are all filled, only video_data takes effect') 102 | params_dict = { 103 | 'ref_text': self._ref_text, 104 | 'config': { 105 | 'video_format': self._video_format, 106 | 'language': self._language, 107 | 'mode': self._mode 108 | } 109 | } 110 | if self._video_data is not None: 111 | params_dict['video_data'] = self._video_data 112 | else: 113 | params_dict['video_url'] = self._video_url 114 | return params_dict 115 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/rasr_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class RasrRequest: 5 | """ 实时语音识别请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | def __init__(self, audio_format, model_property): 7 | """ 8 | 实时语音识别请求初始化 9 | :param audio_format: 音频格式,详见api文档 10 | :param model_property: 属性字符串,language_sampleRate_domain, 如chinese_8k_common,详见api文档 11 | """ 12 | self._audio_format = audio_format 13 | self._property = model_property 14 | self._add_punc = 'no' 15 | self._vad_head = 10000 16 | self._vad_tail = 500 17 | self._max_seconds = 30 18 | self._interim_results = 'no' 19 | self._digit_norm = 'yes' 20 | self._vocabulary_id = None 21 | self._vad_threshold = 0 22 | self._user_words = [] 23 | self._need_word_info = 'no' 24 | 25 | def set_add_punc(self, add_punc): 26 | self._add_punc = add_punc 27 | 28 | def set_digit_norm(self, digit_norm): 29 | self._digit_norm = digit_norm 30 | 31 | def set_vad_head(self, vad_head): 32 | self._vad_head = vad_head 33 | 34 | def set_vad_tail(self, vad_tail): 35 | self._vad_tail = vad_tail 36 | 37 | def set_max_seconds(self, max_seconds): 38 | self._max_seconds = max_seconds 39 | 40 | def set_interim_results(self, interim_results): 41 | self._interim_results = interim_results 42 | 43 | def set_vocabulary_id(self, vocabulary_id): 44 | self._vocabulary_id = vocabulary_id 45 | 46 | def set_vad_threshold(self, vad_threshold): 47 | self._vad_threshold = vad_threshold 48 | 49 | def set_user_words(self, user_words): 50 | self._user_words = user_words 51 | 52 | def set_need_word_info(self, need_word_info): 53 | self._need_word_info = need_word_info 54 | 55 | def construct_params(self): 56 | config = dict() 57 | config['audio_format'] = self._audio_format 58 | config['property'] = self._property 59 | config['add_punc'] = self._add_punc 60 | config['digit_norm'] = self._digit_norm 61 | config['vad_head'] = self._vad_head 62 | config['vad_tail'] = self._vad_tail 63 | config['max_seconds'] = self._max_seconds 64 | config['interim_results'] = self._interim_results 65 | config['vad_threshold'] = self._vad_threshold 66 | config['need_word_info'] = self._need_word_info 67 | if self._user_words is not None and len(self._user_words) > 0: 68 | config['user_words'] = self._user_words 69 | if self._vocabulary_id is not None: 70 | config['vocabulary_id'] = self._vocabulary_id 71 | 72 | params = dict() 73 | params['command'] = 'START' 74 | params['config'] = config 75 | return params 76 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/rtts_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class RttsRequest: 5 | """ 实时语音转写请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | 7 | def __init__(self, text): 8 | """ 9 | 实时语音转写请求初始化 10 | :param audio_format: 音频格式,详见api文档 11 | :param model_property: 属性字符串,language_sampleRate_domain, 如chinese_8k_common,详见api文档 12 | """ 13 | self._text = text 14 | self._command = 'START' 15 | self._audio_format = 'pcm' 16 | self._sample_rate = '8000' 17 | self._property = 'chinese_xiaoyan_common' 18 | self._speed = 0 19 | self._pitch = 0 20 | self._volume = 50 21 | 22 | def set_command(self, command): 23 | self._command = command 24 | 25 | def set_audio_format(self, audio_format): 26 | self._audio_format = audio_format 27 | 28 | def set_sample_rate(self, sample_rate): 29 | self._sample_rate = sample_rate 30 | 31 | def set_property(self, property): 32 | self._property = property 33 | 34 | def set_speed(self, speed): 35 | self._speed = speed 36 | 37 | def set_pitch(self, pitch): 38 | self._pitch = pitch 39 | 40 | def set_volume(self, volume): 41 | self._volume = volume 42 | 43 | def construct_params(self): 44 | config = dict() 45 | config['speed'] = self._speed 46 | config['pitch'] = self._pitch 47 | config['audio_format'] = self._audio_format 48 | config['sample_rate'] = self._sample_rate 49 | config['property'] = self._property 50 | config['volume'] = self._volume 51 | 52 | params = dict() 53 | params['command'] = self._command 54 | params['config'] = config 55 | params['text'] = self._text 56 | return params 57 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/sis_config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class SisConfig: 5 | """ client配置参数,包括超时、代理 """ 6 | def __init__(self): 7 | self.connect_timeout = 10 8 | self.read_timeout = 10 9 | self.connect_lost_timeout = 10 10 | self.proxy = None 11 | self.certificate_check = False 12 | 13 | def set_certificate_check(self, certificate_check): 14 | self.certificate_check = certificate_check 15 | 16 | def get_certificate_check(self): 17 | return self.certificate_check 18 | 19 | def set_connect_timeout(self, timeout): 20 | """ 21 | 设置连接超时 22 | :param timeout: seconds 23 | """ 24 | self.connect_timeout = timeout 25 | 26 | def get_connect_timeout(self): 27 | """ 28 | 返回连接超时时间 29 | :return: connect_timeout, 单位秒 30 | """ 31 | return self.connect_timeout 32 | 33 | def set_read_timeout(self, timeout): 34 | """ 35 | 设置读取超时 36 | :param timeout: seconds 37 | """ 38 | self.read_timeout = timeout 39 | 40 | def get_read_timeout(self): 41 | """ 42 | 返回读取超时 43 | :return: read_timeout, 单位秒 44 | """ 45 | return self.read_timeout 46 | 47 | def set_proxy(self, proxy): 48 | """ 49 | 设置代理 50 | :param proxy: 格式为list,[host, port] 或 [host, port, username, password] 51 | """ 52 | self.proxy = proxy 53 | 54 | def get_proxy(self): 55 | """ 56 | 返回代理 57 | :return: proxy 58 | """ 59 | return self.proxy 60 | 61 | def set_connect_lost_timeout(self, timeout): 62 | """ 63 | 设置connect lost 超时, 在并发满足要求下不需要设置此参数 64 | :param timeout: seconds 65 | """ 66 | self.connect_lost_timeout = timeout 67 | 68 | def get_connect_lost_timeout(self): 69 | """ 70 | 返回connnect lost超时 71 | :return: connect_lost_timeout, 单位秒 72 | """ 73 | return self.connect_lost_timeout 74 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/bean/tts_request.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class TtsCustomRequest: 5 | """ 语音合成请求,除了初始化必选参数外,其他参数均可不配置使用默认 """ 6 | def __init__(self, text): 7 | """ 8 | 语音合成请求初始化 9 | :param text: 需要合成的文本 10 | """ 11 | self._text = text 12 | self._audio_format = 'wav' 13 | self._property = 'chinese_xiaoyan_common' 14 | self._sample_rate = '8000' 15 | self._speed = 0 16 | self._pitch = 0 17 | self._volume = 50 18 | self._saved = False 19 | self._saved_path = '' 20 | 21 | def set_audio_format(self, audio_format): 22 | self._audio_format = audio_format 23 | 24 | def set_volume(self, volume): 25 | self._volume = volume 26 | 27 | def set_sample_rate(self, sample_rate): 28 | self._sample_rate = sample_rate 29 | 30 | def set_property(self, model_property): 31 | self._property = model_property 32 | 33 | def set_pitch(self, pitch): 34 | self._pitch = pitch 35 | 36 | def set_speed(self, speed): 37 | self._speed = speed 38 | 39 | def set_saved(self, saved): 40 | self._saved = saved 41 | 42 | def set_saved_path(self, saved_path): 43 | self._saved_path = saved_path 44 | 45 | def get_saved(self): 46 | return self._saved 47 | 48 | def get_saved_path(self): 49 | return self._saved_path 50 | 51 | def construct_params(self): 52 | config = dict() 53 | config['audio_format'] = self._audio_format 54 | config['sample_rate'] = self._sample_rate 55 | config['property'] = self._property 56 | config['speed'] = self._speed 57 | config['pitch'] = self._pitch 58 | config['volume'] = self._volume 59 | 60 | params = dict() 61 | params['text'] = self._text 62 | params['config'] = config 63 | return params 64 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/client/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/client/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/client/asr_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.auth import aksk_service 4 | from huaweicloud_sis.bean.asr_request import AsrCustomLongRequest 5 | from huaweicloud_sis.bean.asr_request import AsrCustomShortRequest 6 | from huaweicloud_sis.utils.logger_utils import logger 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | from huaweicloud_sis.client.rasr_client import RasrClient 10 | 11 | 12 | class AsrCustomizationClient: 13 | """ 语音识别client """ 14 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 15 | """ 16 | 语音识别client初始化 17 | :param ak: ak 18 | :param sk: sk 19 | :param region: 区域,如cn-north-4 20 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 21 | :param service_endpoint: 终端节点,可不填使用默认即可 22 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 23 | """ 24 | self._ak = ak 25 | self._sk = sk 26 | self._region = region 27 | self._project_id = project_id 28 | if service_endpoint is None: 29 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 30 | else: 31 | self._service_endpoint = service_endpoint 32 | if sis_config is None: 33 | self._sis_config = SisConfig() 34 | else: 35 | self._sis_config = sis_config 36 | 37 | def get_short_response(self, request): 38 | """ 39 | 一句话识别接口 40 | :param request: 一句话识别请求AsrCustomShortRequest 41 | :return: 一句话识别响应结果,返回为json格式 42 | """ 43 | if not isinstance(request, AsrCustomShortRequest): 44 | error_msg = 'the parameter in \'get_short_response(request)\' should be AsrCustomShortRequest class' 45 | logger.error(error_msg) 46 | raise ClientException(error_msg) 47 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/short-audio' 48 | params = request.construct_params() 49 | headers = {'Content-Type': 'application/json'} 50 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 51 | return result 52 | 53 | def submit_job(self, request): 54 | """ 55 | 录音文件识别,提交任务接口 56 | :param request: 录音文件识别请求 57 | :return: job_id 58 | """ 59 | if not isinstance(request, AsrCustomLongRequest): 60 | error_msg = 'the parameter in \'submit_job(request)\' should be AsrCustomLongRequest class' 61 | logger.error(error_msg) 62 | raise ClientException(error_msg) 63 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/transcriber/jobs' 64 | headers = {'Content-Type': 'application/json'} 65 | params = request.construct_parameter() 66 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 67 | if 'job_id' not in result: 68 | error_msg = 'The result of long audio transcription doesn\'t contain key job_id, result is ' % result 69 | logger.error(error_msg) 70 | raise ClientException(error_msg) 71 | return result['job_id'] 72 | 73 | def get_long_response(self, job_id): 74 | """ 75 | 录音文件识别状态查询接口 76 | :param job_id: job_id 77 | :return: 返回的结果,json格式 78 | """ 79 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/transcriber/jobs/' + job_id 80 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'GET', self._sis_config) 81 | return result 82 | 83 | 84 | class SasrWebsocketClient(RasrClient): 85 | def __init__(self, user_name=None, password=None, domain_name=None, region=None, project_id=None, callback=None, 86 | config=SisConfig(), service_endpoint=None, token_url=None, retry_sleep_time=1, ak=None, sk=None, 87 | use_aksk=False): 88 | super().__init__(user_name, password, domain_name, region, project_id, callback, config, service_endpoint, 89 | token_url, retry_sleep_time, ak, sk, use_aksk) -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/client/flash_lasr_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.bean.sis_config import SisConfig 4 | from huaweicloud_sis.bean.flash_lasr_request import FlashLasrRequest 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.exception.exceptions import ClientException 7 | from huaweicloud_sis.auth import aksk_service 8 | 9 | 10 | class FlashLasrClient: 11 | """ 录音文件极速版 client """ 12 | 13 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 14 | """ 15 | 录音文件极速版client初始化 16 | :param ak: ak 17 | :param sk: sk 18 | :param region: 区域,如cn-north-4 19 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 20 | :param service_endpoint: 终端节点,可不填使用默认即可 21 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 22 | """ 23 | self._ak = ak 24 | self._sk = sk 25 | self._region = region 26 | self._project_id = project_id 27 | if service_endpoint is None: 28 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 29 | else: 30 | self._service_endpoint = service_endpoint 31 | if sis_config is None: 32 | self._sis_config = SisConfig() 33 | else: 34 | self._sis_config = sis_config 35 | 36 | def get_flash_lasr_result(self, request): 37 | """ 38 | 录音文件极速版接口 39 | :param request: 录音文件极速版请求 40 | :return: 响应结果,返回为json格式 41 | """ 42 | if not isinstance(request, FlashLasrRequest): 43 | error_msg = 'the parameter in flash lasr should be FlashLasrRequest class' 44 | logger.error(error_msg) 45 | raise ClientException(error_msg) 46 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/flash' 47 | query_url = url + request.construct_params() 48 | headers = {'Content-Type': 'application/json'} 49 | result = aksk_service.aksk_connect(self._ak, self._sk, query_url, headers, None, 'POST', self._sis_config) 50 | return result -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/client/hot_word_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.bean.hot_word_request import HotWordRequest 4 | from huaweicloud_sis.bean.sis_config import SisConfig 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.auth import aksk_service 7 | from huaweicloud_sis.exception.exceptions import ClientException, ServerException 8 | import json 9 | 10 | 11 | class HotWordClient: 12 | """ 热词client,可用于创建热词表、更新热词表、查询热词表列表、查询热词表、删除热词表 """ 13 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 14 | """ 15 | 口语评测client初始化 16 | :param ak: ak 17 | :param sk: sk 18 | :param region: 区域,如cn-north-4 19 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 20 | :param service_endpoint: 终端节点,可不填使用默认即可 21 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 22 | """ 23 | self._ak = ak 24 | self._sk = sk 25 | self._region = region 26 | self._project_id = project_id 27 | if service_endpoint is None: 28 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 29 | else: 30 | self._service_endpoint = service_endpoint 31 | if sis_config is None: 32 | self._sis_config = SisConfig() 33 | else: 34 | self._sis_config = sis_config 35 | 36 | def create(self, request): 37 | """ 38 | 创建热词表 39 | :param request: 热词表请求 40 | :return: 热词表id 41 | """ 42 | if not isinstance(request, HotWordRequest): 43 | logger.error('the parameter in \'create_hot_word(request)\' should be HotWordRequest class') 44 | raise ClientException('the parameter in \'create_hot_word(request)\' should be HotWordRequest class') 45 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies' 46 | headers = {'Content-Type': 'application/json'} 47 | params = request.construct_params() 48 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 49 | return result 50 | 51 | def update(self, request, vocabulary_id): 52 | """ 53 | 更新热词表 54 | :param request: 热词表请求 55 | :param vocabulary_id: 热词表id,更新时一定要保证该热词表存在 56 | :return: 热词表id 57 | """ 58 | if not isinstance(request, HotWordRequest): 59 | logger.error('the parameter in \'update_hot_word(request)\' should be HotWordRequest class') 60 | raise ClientException('the parameter in \'update_hot_word(request)\' should be HotWordRequest class') 61 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id 62 | headers = {'Content-Type': 'application/json'} 63 | params = request.construct_params() 64 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'PUT', self._sis_config) 65 | return result 66 | 67 | def query_list(self): 68 | """ 69 | 查询热词表列表信息 70 | :return: 热词表列表信息 71 | """ 72 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies' 73 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'GET', self._sis_config) 74 | return result 75 | 76 | def query_by_vocabulary_id(self, vocabulary_id): 77 | """ 78 | 根据vocabulary_id查询热词表信息 79 | :param vocabulary_id: 热词表id,使用前一定要保证其已存在。 80 | :return: 热词表信息 81 | """ 82 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id 83 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'GET', self._sis_config) 84 | return result 85 | 86 | def delete(self, vocabulary_id): 87 | """ 88 | 根据vocabulary_id删除指定的热词表 89 | :param vocabulary_id: 热词表id,使用前一定要保证其已存在。 90 | :return: 正常删除返回结果为空,出现错误则返回error_code和error_msg 91 | """ 92 | url = self._service_endpoint + '/v1/' + self._project_id + '/asr/vocabularies/' + vocabulary_id 93 | result = aksk_service.aksk_connect(self._ak, self._sk, url, None, None, 'DELETE', self._sis_config) 94 | if result is None: 95 | return result 96 | result_text = result.text 97 | return json.loads(result_text) 98 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/client/pa_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.auth import aksk_service 4 | from huaweicloud_sis.bean.pa_request import PaAudioRequest 5 | from huaweicloud_sis.bean.pa_request import PaVideoRequest 6 | from huaweicloud_sis.utils.logger_utils import logger 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | 10 | 11 | class PaClient: 12 | """ 口语评测 client """ 13 | 14 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 15 | """ 16 | 口语评测client初始化 17 | :param ak: ak 18 | :param sk: sk 19 | :param region: 区域,如cn-north-4 20 | :param project_id: 项目id,可参考https://support.huaweicloud.com/api-sis/sis_03_0008.html 21 | :param service_endpoint: 终端节点,可不填使用默认即可 22 | :param sis_config: 配置信息,包括超时、代理等,可不填使用默认即可。 23 | """ 24 | self._ak = ak 25 | self._sk = sk 26 | self._region = region 27 | self._project_id = project_id 28 | if service_endpoint is None: 29 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 30 | else: 31 | self._service_endpoint = service_endpoint 32 | if sis_config is None: 33 | self._sis_config = SisConfig() 34 | else: 35 | self._sis_config = sis_config 36 | 37 | def assessment_audio(self, request): 38 | """ 39 | 语音评测接口 40 | :param request: 语音评测请求 41 | :return: 响应结果,返回为json格式 42 | """ 43 | if not isinstance(request, PaAudioRequest): 44 | error_msg = 'the parameter in \'assessment_audio(request)\' should be PaAudioRequest class' 45 | logger.error(error_msg) 46 | raise ClientException(error_msg) 47 | url = self._service_endpoint + '/v1/' + self._project_id + '/assessment/audio' 48 | params = request.construct_params() 49 | headers = {'Content-Type': 'application/json'} 50 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 51 | return result 52 | 53 | def assessment_video(self, request): 54 | """ 55 | 多模态评测接口 56 | :param request: 多模态评测请求 57 | :return: 响应结果,返回为json格式 58 | """ 59 | if not isinstance(request, PaVideoRequest): 60 | error_msg = 'the parameter in \'assessment_video(request)\' should be PaVideoRequest class' 61 | logger.error(error_msg) 62 | raise ClientException(error_msg) 63 | url = self._service_endpoint + '/v1/' + self._project_id + '/assessment/video' 64 | headers = {'Content-Type': 'application/json'} 65 | params = request.construct_parameter() 66 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 67 | return result 68 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/client/tts_client.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import json 4 | from huaweicloud_sis.auth import aksk_service 5 | from huaweicloud_sis.bean.tts_request import TtsCustomRequest 6 | from huaweicloud_sis.utils import io_utils 7 | from huaweicloud_sis.exception.exceptions import ClientException 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | from huaweicloud_sis.utils.logger_utils import logger 10 | 11 | 12 | class TtsCustomizationClient: 13 | """ 语音合成client """ 14 | def __init__(self, ak, sk, region, project_id, service_endpoint=None, sis_config=None): 15 | self._ak = ak 16 | self._sk = sk 17 | self._region = region 18 | self._project_id = project_id 19 | if service_endpoint is None: 20 | self._service_endpoint = 'https://sis-ext.' + region + '.myhuaweicloud.com' 21 | else: 22 | self._service_endpoint = service_endpoint 23 | if sis_config is None: 24 | self._sis_config = SisConfig() 25 | else: 26 | self._sis_config = sis_config 27 | 28 | def get_ttsc_response(self, request): 29 | """ 30 | 语音合成接口 31 | :param request: 语音合成请求,TtsCustomRequest 32 | :return: 请求结果,json格式 33 | """ 34 | if not isinstance(request, TtsCustomRequest): 35 | logger.error('the parameter in \'get_ttsc_response(request)\' should be TtsCustomRequest class') 36 | raise ClientException('the parameter in \'get_ttsc_response(request)\' should be TtsCustomRequest class') 37 | url = self._service_endpoint + '/v1/' + self._project_id + '/tts' 38 | params = request.construct_params() 39 | headers = {'Content-Type': 'application/json'} 40 | result = aksk_service.aksk_connect(self._ak, self._sk, url, headers, params, 'POST', self._sis_config) 41 | if 'result' not in result: 42 | error_msg = 'The result of tts customization is invalid. Result is %s ' % json.dumps(result) 43 | logger.error(error_msg) 44 | raise ClientException(error_msg) 45 | if request.get_saved(): 46 | base_str = result['result']['data'] 47 | io_utils.save_audio_from_base64str(base_str, request.get_saved_path()) 48 | result['is_saved'] = True 49 | result['saved_path'] = request.get_saved_path() 50 | return result 51 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/exception/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/exception/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/exception/exceptions.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class ClientException(Exception): 5 | def __init__(self, error_msg): 6 | super().__init__(self, error_msg) 7 | self._error_msg = error_msg 8 | 9 | def get_error_msg(self): 10 | return self._error_msg 11 | 12 | def __str__(self): 13 | return self.get_error_msg() 14 | 15 | 16 | class ServerException(Exception): 17 | def __init__(self, error_code, error_msg): 18 | dict1 = dict() 19 | dict1['error_code'] = error_code 20 | dict1['error_msg'] = error_msg 21 | super().__init__(self, str(dict1)) 22 | self._error_code = error_code 23 | self._error_msg = error_msg 24 | 25 | def get_error_code(self): 26 | return self._error_code 27 | 28 | def get_error_msg(self): 29 | return self._error_msg 30 | 31 | def __str__(self): 32 | return 'error_code: ' + self.get_error_code() + '\t' + 'error_msg: ' + self.get_error_msg() 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GalaxieT/VvTalk/4c8f7c047a9dd864750f636f4010a8a7b0ee8619/setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/utils/__init__.py -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/utils/http_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import requests 4 | import json 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.exception.exceptions import ClientException, ServerException 7 | 8 | requests.packages.urllib3.disable_warnings() 9 | NUM_MAX_RETRY = 5 10 | 11 | 12 | def http_connect(url, header, data, http_method='POST', time_out=5, proxy=None, certificate_check=False): 13 | """ 14 | post请求,带有header信息(用于认证) 15 | :param url: - 16 | :param header: 头部 17 | :param data: post数据 18 | :param time_out: 超时 19 | :param proxy: 代理 20 | :param http_method: http方法,目前支持put、delete、post、get 21 | :param certificate_check: 校验证书 22 | :return: http请求的response 23 | """ 24 | if isinstance(data, dict): 25 | data = json.dumps(data) 26 | if proxy is not None: 27 | proxy = _generate_request_proxy(proxy) 28 | else: 29 | proxy = { 30 | 'http': None, 31 | 'https': None 32 | } 33 | # 加入重试机制 34 | count = 0 35 | resp = None 36 | while count < NUM_MAX_RETRY: 37 | try: 38 | if http_method == 'POST': 39 | resp = requests.post(url, headers=header, data=data, timeout=time_out, verify=certificate_check, 40 | proxies=proxy) 41 | elif http_method == 'GET': 42 | resp = requests.get(url, headers=header, params=data, timeout=time_out, verify=certificate_check, 43 | proxies=proxy) 44 | elif http_method == 'PUT': 45 | resp = requests.put(url, headers=header, data=data, timeout=time_out, verify=certificate_check, 46 | proxies=proxy) 47 | elif http_method == 'DELETE': 48 | resp = requests.delete(url, headers=header, params=data, timeout=time_out, verify=certificate_check, 49 | proxies=proxy) 50 | else: 51 | logger.error('%s is invalid' % http_method) 52 | raise ClientException('%s is invalid' % http_method) 53 | break 54 | except requests.exceptions.RequestException as e: 55 | logger.error('Error occurs in %s, the client will retry 5 times. Error message is %s' % (http_method, e)) 56 | count += 1 57 | if resp is None: 58 | logger.error('%s Response is empety, url is %s' % (http_method, url)) 59 | raise ClientException('%s Response is empety, url is %s' % (http_method, url)) 60 | return resp 61 | 62 | 63 | def parse_resp(resp): 64 | """ 65 | requests响应转化为json格式 66 | :param resp: requests请求返回的响应 67 | :return: json 68 | """ 69 | if resp is None or resp.text is None or resp.text == '': 70 | return None 71 | text = resp.text 72 | try: 73 | result = json.loads(text) 74 | except Exception as e: 75 | error_msg = 'Parsing json failed, the text is %s' % text 76 | logger.error(error_msg) 77 | raise ClientException(error_msg) 78 | if 'error_code' in result and 'error_msg' in result: 79 | error_msg = json.dumps(result) 80 | logger.error(error_msg) 81 | raise ServerException(result['error_code'], result['error_msg']) 82 | return result 83 | 84 | 85 | def generate_scheme_host_uri(url): 86 | if url.find('//') == -1 or url.find('com') == -1: 87 | error_msg = '%s is invalid' % url 88 | logger.error(error_msg) 89 | raise ClientException(error_msg) 90 | split1s = url.split('//') 91 | split2s = split1s[1].split('com') 92 | scheme = split1s[0] + '//' 93 | host = split2s[0] + 'com' 94 | uri = split2s[1] 95 | return scheme, host, uri 96 | 97 | 98 | def _generate_request_proxy(proxy): 99 | if proxy is None: 100 | return proxy 101 | if not isinstance(proxy, list) or (not len(proxy) == 2 and not len(proxy) == 4): 102 | logger.error('Proxy must be list, the format is [host, port] or [host, port, username, password]') 103 | raise ClientException('Proxy must be list, the format is [host, port] or [host, port, username, password]') 104 | proxy_str = str(proxy[0]) + ':' + str(proxy[1]) 105 | if len(proxy) == 2: 106 | proxy = { 107 | 'http': 'http://' + proxy_str, 108 | 'https': 'https://' + proxy_str 109 | } 110 | else: 111 | proxy = { 112 | 'http': 'http://' + str(proxy[2]) + ':' + str(proxy[3]) + '@' + proxy_str, 113 | 'https': 'https://' + str(proxy[2]) + ':' + str(proxy[3]) + '@' + proxy_str 114 | } 115 | return proxy 116 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/utils/io_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import base64 4 | import os 5 | from huaweicloud_sis.utils.logger_utils import logger 6 | from huaweicloud_sis.exception.exceptions import ClientException 7 | 8 | 9 | def encode_file(file_path): 10 | if not os.path.exists(file_path): 11 | logger.error('The Path %s doesn\'t exist' % file_path) 12 | raise ClientException('The Path %s doesn\'t exist' % file_path) 13 | with open(file_path, 'rb') as f: 14 | data = f.read() 15 | base64_data = str(base64.b64encode(data), 'utf-8') 16 | return base64_data 17 | 18 | 19 | def save_audio_from_base64str(base64_str, save_path): 20 | parent_path = os.path.dirname(save_path) 21 | if parent_path != '' and not os.path.exists(parent_path): 22 | os.makedirs(parent_path) 23 | with open(save_path, 'wb') as f: 24 | base64_data = base64.b64decode(base64_str) 25 | f.write(base64_data) 26 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/huaweicloud_sis/utils/logger_utils.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import logging.handlers 4 | 5 | # 获取一个日志logger 6 | logging.basicConfig( 7 | level=logging.INFO, 8 | format='[%(asctime)s] - [%(levelname)s] - [%(message)s]' 9 | ) 10 | # 设置handler 11 | file_handler = logging.handlers.RotatingFileHandler('huaweicloud_sis.log', maxBytes=1024*1024, 12 | backupCount=5, encoding='utf-8') 13 | file_handler.setLevel(logging.INFO) 14 | file_handler.setFormatter(logging.Formatter('[%(asctime)s] - [%(levelname)s] - [%(message)s]')) 15 | 16 | # 添加file_handler 17 | logger = logging.getLogger('huaweicloud_sis') 18 | logger.addHandler(file_handler) 19 | -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/intl_demo/asr_customization_demo.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from huaweicloud_sis.client.asr_client import AsrCustomizationClient 4 | from huaweicloud_sis.bean.asr_request import AsrCustomShortRequest 5 | from huaweicloud_sis.exception.exceptions import ClientException 6 | from huaweicloud_sis.exception.exceptions import ServerException 7 | from huaweicloud_sis.utils import io_utils 8 | from huaweicloud_sis.bean.sis_config import SisConfig 9 | import json 10 | 11 | # personal information 12 | ak = '' 13 | sk = '' 14 | region = '' # region, such as ap-southeast-3 15 | project_id = '' # project_id, refer to https://support.huaweicloud.com/intl/en-us/api-sis/sis_03_0008.html 16 | 17 | path = '' # the file path,such as D:/test.wav. The sample rate should be same as pathProperty. 18 | path_audio_format = '' # audio format,such as wav. Please refer to api document 19 | path_property = '' # language_sampleRate_domain, such as english_8k_common. Please refer to api document 20 | 21 | 22 | def asrc_short_example(): 23 | """ Sentence Transcription demo """ 24 | # step1 initialize client 25 | config = SisConfig() 26 | config.set_connect_timeout(10) 27 | config.set_read_timeout(10) 28 | # set proxy, please make sure that it can take effects before use. 29 | # proxy = [host, port] or proxy = [host, port, username, password] 30 | # config.set_proxy(proxy) 31 | asr_client = AsrCustomizationClient(ak, sk, region, project_id, sis_config=config) 32 | 33 | # step2 set the parameters 34 | base64_str = io_utils.encode_file(path) # the audio file will be converted to base64 str 35 | asr_request = AsrCustomShortRequest(path_audio_format, path_property, base64_str) 36 | # all parameters are optional. 37 | # set punctuation, yes or no, default no. 38 | asr_request.set_add_punc('yes') 39 | # sentence transcription doesn't support hot word now. So the method of set_vocabulary_id makes no sense. 40 | 41 | # step3 send request, get response 42 | result = asr_client.get_short_response(asr_request) 43 | print(json.dumps(result, indent=2, ensure_ascii=False)) 44 | 45 | 46 | if __name__ == '__main__': 47 | try: 48 | asrc_short_example() 49 | except ClientException as e: 50 | print(e) 51 | except ServerException as e: 52 | print(e) -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/readme_cn.txt: -------------------------------------------------------------------------------- 1 | 安装: 2 | 1. 请确认已安装Python包管理工具setuptools,请确认已安装requests和websocket-client,可通过“pip list”命令查看已安装列表。如果没有安装,请使用以下命令安装 3 | pip install setuptools 4 | pip install requests 5 | pip install websocket-client 6 | 2. 进入sdk的目录,执行以下安装命令: 7 | python setup.py install 8 | 9 | 使用步骤: 10 | 1. “cn_demo”文件夹:存放中国站上线接口调用示例代码,代码文件和接口对应关系如下: 11 | 一句话识别Http接口 : sasr_demo.py 12 | 一句话识别Websocket接口 : sasr_websocket_demo.py 13 | 录音文件识别 : lasr_demo.py 14 | 录音文件极速版 : flash_lasr_demo.py 15 | 实时语音转写 : rasr_demo.py 16 | 语音合成 : tts_demo.py 17 | 热词使用 : hot_word_demo.py 18 | 口语评测 & 多模态评测 : pa_demo.py 19 | 2. “intl_demo”文件夹:存放国际站上线接口调用示例代码,代码文件和接口对应关系如下: 20 | 一句话识别 : asr_customization_demo.py 21 | 3. “data”文件夹:存放示例音频可供参考使用。 22 | 23 | 注意: 24 | 1. python sdk目前仅支持python3,暂不支持python2 25 | 2. 中国站使用中国站账户登录,仅支持识别中文;国际站使用国际站账号登录,仅支持识别英文。 26 | 3. 国际站一句话识别暂时不支持热词功能,不支持digit_norm属性。 -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/readme_en.txt: -------------------------------------------------------------------------------- 1 | intall: 2 | 1. Please make sure you have installed "setuptools", "requests" and "websocket-client",you can run "pip list" to see the installed packages, and you can run the following commands to install packages. 3 | pip install setuptools 4 | pip install requests 5 | pip install websocket-client 6 | 2. Go to the sdk directory and run the command: 7 | python setup.py install 8 | 9 | usage: 10 | 1. In folder "cn_demo", the code show how to use the SDK in chinese region. 11 | 2. In folder "intl_demo", the code show how to use the SDK in international region. 12 | 3. In folder "data", the audio files are examples for users. 13 | 14 | warn: 15 | 1. The SDK can only be runned in python3, and the sdk is incompatible with python2. 16 | 2. In chinese region, the api only support recognizing chinese. In international region, the api only support recognzing english. 17 | 3. In international region, sentence transcription doesn't support hot word or digit_norm. -------------------------------------------------------------------------------- /setup_install/huaweicloud-python-sdk-sis-1.7.1/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup( 4 | name='huaweicloud-python-sdk-sis', 5 | version='1.7.1', 6 | author='Huaweicloud SIS', 7 | packages=find_packages(), 8 | zip_safe=False, 9 | description='sis python sdk', 10 | long_description='sis python sdk', 11 | install_requires=['websocket-client', 'requests'], 12 | license='Apache-2.0', 13 | keywords=('sis', 'sdk', 'python'), 14 | platforms='Independant' 15 | ) --------------------------------------------------------------------------------