1. 进一步拓展了语音识别,目前可以从sd卡导入模型,避免了model文件占用flash分区大小
2. 进一步修改了语音识别,关闭了关键词唤醒功能,只保留了指令识别功能 3. 构建了业务层的基本框架(增加了底层驱动对于的C++兼容),业务代码采用C++编写,启用了RTTI(运行时类型识别)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
from pypinyin import pinyin, Style
|
||||
import argparse
|
||||
import re
|
||||
|
||||
def chinese_to_pinyin(text):
|
||||
# Use regular expression to extract Chinese characters
|
||||
chinese_text = ''.join(re.findall(r'[\u4e00-\u9fa5]', text))
|
||||
|
||||
out = "static const sr_cmd_t sr_commands[] = {\n"
|
||||
enum = "enum {\n"
|
||||
|
||||
cmd_id = 0
|
||||
text_list = chinese_text.split(";")
|
||||
|
||||
for item in text_list:
|
||||
item = item.strip() # Remove leading and trailing spaces
|
||||
if not item:
|
||||
continue
|
||||
|
||||
item = item.split(",")
|
||||
phrase_id = 0
|
||||
pinyin_list_all = []
|
||||
for phrase in item:
|
||||
phrase = phrase.strip() # Remove leading and trailing spaces
|
||||
if not phrase:
|
||||
continue
|
||||
|
||||
# Convert Chinese phrase to pinyin with spaces between each syllable
|
||||
pinyin_list = pinyin(phrase, style=Style.NORMAL, heteronym=False)
|
||||
# Join pinyin list with spaces
|
||||
phoneme = ' '.join([py[0] for py in pinyin_list])
|
||||
|
||||
out += f' {{ {cmd_id}, "{phoneme}", "{phoneme}" }},\n'
|
||||
|
||||
if phrase_id == 0:
|
||||
enum += f' SR_CMD_{phoneme.upper().replace(" ", "_")},\n'
|
||||
|
||||
phrase_id += 1
|
||||
|
||||
cmd_id += 1
|
||||
|
||||
out += "};\n"
|
||||
enum += "};\n"
|
||||
|
||||
print(enum)
|
||||
print(out)
|
||||
|
||||
return out
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(prog="Chinese Speech Commands to Pinyin")
|
||||
parser.add_argument("text", type=str, default=None, help="input text")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.text is not None:
|
||||
chinese_to_pinyin(args.text)
|
||||
Reference in New Issue
Block a user