Repository navigation
Export KittenTTS models #3604
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
Export KittenTTS models #3604
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env python3 | ||
| # Synchronize sherpa-onnx-tts.node.js from sherpa-onnx-tts.js. | ||
| # The only difference should be the export mechanism: | ||
| # sherpa-onnx-tts.js uses ES module: export { ... } | ||
| # sherpa-onnx-tts.node.js uses CommonJS: module.exports = { ... } | ||
|
|
||
| import os | ||
| import re | ||
|
|
||
| dir_path = os.path.dirname(os.path.abspath(__file__)) | ||
| src = os.path.join(dir_path, "sherpa-onnx-tts.js") | ||
| dst = os.path.join(dir_path, "sherpa-onnx-tts.node.js") | ||
|
|
||
| with open(src) as f: | ||
| content = f.read() | ||
|
|
||
| # Replace ES module export with CommonJS module.exports | ||
| content = re.sub( | ||
| r"export \{[^}]*\};", | ||
| """if (typeof process == 'object' && typeof process.versions == 'object' &&\\n typeof process.versions.node == 'string') {\\n module.exports = {\\n createOfflineTts,\\n getDefaultOfflineTtsModelType,\\n };\\n}""", | ||
| content, | ||
| ) | ||
|
Comment on lines
+18
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The replacement = (\n "if (typeof process == 'object' && typeof process.versions == 'object' &&\n"\n " typeof process.versions.node == 'string') {\n"\n " module.exports = {\n"\n " createOfflineTts,\n"\n " getDefaultOfflineTtsModelType,\n"\n " };\n"\n "}"\n)\ncontent = re.sub(r"export\\s+\\{[^}]*\\};", replacement, content) |
||
|
|
||
| with open(dst, "w") as f: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| f.write(content) | ||
|
|
||
| print(f"Updated {dst} from {src}") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended to specify the encoding (e.g.,
encoding="utf-8") when opening files to ensure consistent behavior across different platforms and locales.