Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 #715

Merged
merged 52 commits into from
Oct 26, 2023
Merged

v3.0 #715

Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9572592
v3.0 C libs (#661)
laves Oct 6, 2023
f2ea886
Fix bb libs
Oct 6, 2023
7281719
MCU - v3.0 (#664)
mrrostam Oct 11, 2023
88006f3
thread patch
laves Oct 13, 2023
e8ad263
bb
laves Oct 13, 2023
8c0935f
update submodules
laves Oct 16, 2023
5857fa0
update submodules
laves Oct 16, 2023
4cd8699
update submodules
ksyeo1010 Oct 17, 2023
0bf5b30
update submodules
ksyeo1010 Oct 18, 2023
e6b5d79
new api changes
ksyeo1010 Oct 6, 2023
57bc60e
update rust
ksyeo1010 Oct 18, 2023
8ffc2e8
update test
ksyeo1010 Oct 19, 2023
e4575a5
fix test
ksyeo1010 Oct 19, 2023
1be99c4
fix actions
ksyeo1010 Oct 19, 2023
f3263e6
fix build
ksyeo1010 Oct 19, 2023
cfa6592
update version
ksyeo1010 Oct 19, 2023
7a002f4
update submodule
ksyeo1010 Oct 19, 2023
30c0843
update ppn
laves Oct 19, 2023
aa295e0
update rhino
laves Oct 19, 2023
1b00d7f
v3.0 python (#672)
laves Oct 20, 2023
a5b425a
v3.0 android (#673)
laves Oct 20, 2023
c682055
v3.0 dotnet (#674)
laves Oct 20, 2023
706cbcb
submodule
laves Oct 20, 2023
2a05c15
v3.0 ios (#676)
laves Oct 23, 2023
bed23ed
v3.0 unity (#693)
ksyeo1010 Oct 23, 2023
f9caf3e
v3.0 web (#680)
ksyeo1010 Oct 23, 2023
0399f22
update submodule
ksyeo1010 Oct 24, 2023
22021c0
v3.0 flutter (#694)
laves Oct 24, 2023
8ffcc4e
v3.0 go (#675)
ksyeo1010 Oct 24, 2023
c837399
v3.0 java (#679)
ksyeo1010 Oct 24, 2023
7feed27
v3.0 rn (#696)
laves Oct 24, 2023
f4f1c41
v3.0 web UI (#695)
ksyeo1010 Oct 24, 2023
dc56a67
v3.0 c (#689)
ksyeo1010 Oct 24, 2023
afbaad1
Merge pull request #691 from Picovoice/v3.0-rust
ErisMik Oct 24, 2023
26314a9
minor demo changes
laves Oct 24, 2023
0683add
v3.0 node (#690)
ksyeo1010 Oct 25, 2023
de69ec1
python release (#701)
laves Oct 25, 2023
4115cb2
podfile fix
laves Oct 25, 2023
c5ce62f
update package (#704)
ksyeo1010 Oct 25, 2023
08a3642
v3.0 web release (#705)
ksyeo1010 Oct 25, 2023
bd3c60a
v3.0 java release (#706)
ksyeo1010 Oct 25, 2023
f8799a2
v3.0 go release (#707)
ksyeo1010 Oct 25, 2023
465f630
v3.0 rust release (#709)
ksyeo1010 Oct 25, 2023
5ba627e
v3.0 web ui release (#712)
ksyeo1010 Oct 25, 2023
4b13c6d
just android (#703)
laves Oct 25, 2023
0eb0b69
dotnet release (#708)
laves Oct 25, 2023
209d3a6
v3.0 node release (#711)
ksyeo1010 Oct 25, 2023
85d38c2
ios release (#710)
laves Oct 25, 2023
8ffa416
flutter release (#713)
laves Oct 25, 2023
3a226e8
rn release (#714)
laves Oct 26, 2023
b063475
submodule update
laves Oct 26, 2023
1faba8d
update submodules to master
laves Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MCU - v3.0 (#664)
  • Loading branch information
mrrostam authored Oct 11, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7281719476a7293c2571cf90924ef4e825a2ae85
137 changes: 69 additions & 68 deletions demo/mcu/generate_pv_params_file.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

HEADER = """
/*
Copyright 2020-2022 Picovoice Inc.
Copyright 2020-2023 Picovoice Inc.

You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
file accompanying this source.
@@ -38,112 +38,113 @@
"""

LANGUAGE_CODE_TO_NAME = {
'ar': 'arabic',
'nl': 'dutch',
'en': 'english',
'fr': 'french',
'de': 'german',
'hi': 'hindi',
'it': 'italian',
'ja': 'japanese',
'ko': 'korean',
'zh': 'mandarin',
'pl': 'polish',
'pt': 'portuguese',
'ru': 'russian',
'es': 'spanish',
'sv': 'swedish',
'vn': 'vietnamese',
"ar": "arabic",
"de": "german",
"en": "english",
"es": "spanish",
"fa": "farsi",
"fr": "french",
"hi": "hindi",
"it": "italian",
"ja": "japanese",
"ko": "korean",
"nl": "dutch",
"pl": "polish",
"pt": "portuguese",
"ru": "russian",
"sv": "swedish",
"vn": "vietnamese",
"zh": "mandarin",
}


def generate_pv_params(model_files, header_file_folders):
script_dir = os.path.dirname(os.path.abspath(__file__))
repo_dir = os.path.join(script_dir, '../..')
repo_dir = os.path.join(script_dir, "../..")

for header_file_path in header_file_folders:
header_file = os.path.join(os.path.dirname(__file__), header_file_path, 'pv_params.h')
with open(header_file, 'w') as f_out:
header_file = os.path.join(os.path.dirname(__file__), header_file_path, "pv_params.h")
with open(header_file, "w") as f_out:
f_out.write(HEADER)

for language, ppn_rhn_models in model_files.items():

if language == 'en':
ppn_dir = os.path.join(repo_dir, 'resources/porcupine/resources/keyword_files/cortexm')
rhn_dir = os.path.join(repo_dir, f'resources/rhino/resources/contexts/cortexm')
if language == "en":
ppn_dir = os.path.join(repo_dir, "resources/porcupine/resources/keyword_files/cortexm")
rhn_dir = os.path.join(repo_dir, f"resources/rhino/resources/contexts/cortexm")
else:
ppn_dir = os.path.join(repo_dir, f'resources/porcupine/resources/keyword_files_{language}/cortexm')
rhn_dir = os.path.join(repo_dir, f'resources/rhino/resources/contexts_{language}/cortexm')
ppn_dir = os.path.join(repo_dir, f"resources/porcupine/resources/keyword_files_{language}/cortexm")
rhn_dir = os.path.join(repo_dir, f"resources/rhino/resources/contexts_{language}/cortexm")

f_out.write(f'\n#if defined(__PV_LANGUAGE_{LANGUAGE_CODE_TO_NAME[language].upper()}__)\n\n')
f_out.write(f"\n#if defined(__PV_LANGUAGE_{LANGUAGE_CODE_TO_NAME[language].upper()}__)\n\n")

keyword_file_path = os.path.join(ppn_dir, ppn_rhn_models['wake_word'] + '_cortexm.ppn')
keyword_file_path = os.path.join(ppn_dir, ppn_rhn_models["wake_word"] + "_cortexm.ppn")
ppn_c_array = ppn_to_c_array(keyword_file_path)
f_out.write('// wake-word = %s \n' % ppn_rhn_models['wake_word'])
f_out.write('static const uint8_t KEYWORD_ARRAY[] = {\n')
f_out.write('\n'.join(ppn_c_array))
f_out.write('};\n\n')
f_out.write("// wake-word = %s \n" % ppn_rhn_models["wake_word"])
f_out.write("static const uint8_t KEYWORD_ARRAY[] = {\n")
f_out.write("\n".join(ppn_c_array))
f_out.write("};\n\n")

context_file_path = os.path.join(rhn_dir, ppn_rhn_models['context'] + '_cortexm.rhn')
context_file_path = os.path.join(rhn_dir, ppn_rhn_models["context"] + "_cortexm.rhn")
ppn_c_array = ppn_to_c_array(context_file_path)
f_out.write('// context = %s \n' % ppn_rhn_models['context'])
f_out.write('static const uint8_t CONTEXT_ARRAY[] = {\n')
f_out.write('\n'.join(ppn_c_array))
f_out.write('};\n')
f_out.write("// context = %s \n" % ppn_rhn_models["context"])
f_out.write("static const uint8_t CONTEXT_ARRAY[] = {\n")
f_out.write("\n".join(ppn_c_array))
f_out.write("};\n")

f_out.write(f'\n#endif // __PV_LANGUAGE_{LANGUAGE_CODE_TO_NAME[language].upper()}__\n')
f_out.write(f"\n#endif // __PV_LANGUAGE_{LANGUAGE_CODE_TO_NAME[language].upper()}__\n")

f_out.write(FOOTER)


def ppn_to_c_array(binary_file_path):
indent = 8
line_width = 120
with open(binary_file_path, 'rb') as f:
with open(binary_file_path, "rb") as f:
array = f.read()
res = list()
array = ['0x%s' % z.hex() for z in struct.unpack('%dc' % len(array), array)]
row = ' ' * indent
array = ["0x%s" % z.hex() for z in struct.unpack("%dc" % len(array), array)]
row = " " * indent
last_x = 0
for x in array:
if len(row) >= line_width:
row = row.rsplit(', ', maxsplit=1)[0] + ','
row = row.rsplit(", ", maxsplit=1)[0] + ","
res.append(row)
row = ' ' * indent + last_x
if row != ' ' * indent:
row += ', '
row = " " * indent + last_x
if row != " " * indent:
row += ", "
row += x
last_x = x
if row != ' ' * indent:
if row != " " * indent:
res.append(row)
res.append('')
res.append("")
return res


if __name__ == '__main__':
if __name__ == "__main__":
models = {
'en': {'wake_word': 'picovoice', 'context': 'smart_lighting'},
'de': {'wake_word': 'hey computer', 'context': 'beleuchtung'},
'es': {'wake_word': 'hola computadora', 'context': 'iluminación_inteligente'},
'fr': {'wake_word': 'bonjour ordinateur', 'context': 'éclairage_intelligent'},
'it': {'wake_word': 'ciao computer', 'context': 'illuminazione'},
'ja': {'wake_word': 'konnichiwa konpyūtā', 'context': 'sumāto_shōmei'},
'ko': {'wake_word': 'annyeong keompyuteo', 'context': 'seumateu_jomyeong'},
'pt': {'wake_word': 'olá computador', 'context': 'luz_inteligente'},
'ru': {'wake_word': 'privet kompyuter', 'context': 'simple_context_ru'},
'nl': {'wake_word': 'hallo computer', 'context': 'simple_context_nl'},
'hi': {'wake_word': 'namaste putra', 'context': 'simple_context_hi'},
'ar': {'wake_word': 'coffee', 'context': 'simple_context_ar'},
'pl': {'wake_word': 'cześć komputer', 'context': 'simple_context_pl'},
'sv': {'wake_word': 'hej dator', 'context': 'simple_context_sv'},
'vn': {'wake_word': 'xin chào máy tính', 'context': 'simple_context_vn'},
'zh': {'wake_word': 'nǐ hǎo diànnǎo', 'context': 'simple_context_zh'},
"ar": {"wake_word": "مرحبا الكمبيوتر", "context": "simple_context_ar"},
"de": {"wake_word": "hey computer", "context": "beleuchtung"},
"en": {"wake_word": "picovoice", "context": "smart_lighting"},
"es": {"wake_word": "hola computadora", "context": "iluminación_inteligente"},
"fa": {"wake_word": "سلام رایانه", "context": "simple_context_fa"},
"fr": {"wake_word": "bonjour ordinateur", "context": "éclairage_intelligent"},
"hi": {"wake_word": "नमस्ते कंप्यूटर", "context": "simple_context_hi"},
"it": {"wake_word": "ciao computer", "context": "illuminazione"},
"ja": {"wake_word": "こんにちは コンピューター", "context": "sumāto_shōmei"},
"ko": {"wake_word": "안녕 컴퓨터", "context": "seumateu_jomyeong"},
"nl": {"wake_word": "hallo computer", "context": "simple_context_nl"},
"pl": {"wake_word": "cześć komputer", "context": "simple_context_pl"},
"pt": {"wake_word": "olá computador", "context": "luz_inteligente"},
"ru": {"wake_word": "привет компьютер", "context": "simple_context_ru"},
"sv": {"wake_word": "hej dator", "context": "simple_context_sv"},
"vn": {"wake_word": "xin chào máy tính", "context": "simple_context_vn"},
"zh": {"wake_word": "你好电脑", "context": "simple_context_zh"},
}
include_folders = [
'imxrt1050/imxrt1050-evkb/inc',
'stm32f407/stm32f407g-disc1/Inc/',
'stm32f411/stm32f411e-disco/Inc/',
'stm32f769/stm32f769i-disco/Inc/',
"imxrt1050/imxrt1050-evkb/inc",
"stm32f407/stm32f407g-disc1/Inc/",
"stm32f411/stm32f411e-disco/Inc/",
"stm32f769/stm32f769i-disco/Inc/",
]

generate_pv_params(models, include_folders)
Loading