Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/export-kitten.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: export-kitten-to-onnx
on:
push:
branches:
- kitten-0.2
- update-kitten

workflow_dispatch:

Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
echo "$d exists"
rm -rf huggingface

git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d huggingface
git clone https://csukuangfj2:$HF_TOKEN@huggingface.co/csukuangfj2/$d huggingface
cd huggingface
rm -rf ./*

Expand All @@ -194,5 +194,5 @@ jobs:
git status

git commit -m "add models"
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d main || true
git push https://csukuangfj2:$HF_TOKEN@huggingface.co/csukuangfj2/$d main || true
done
7 changes: 7 additions & 0 deletions wasm/tts/sherpa-onnx-tts.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,13 @@ function createOfflineTts(Module, myConfig) {
offlineTtsPocketModelConfig.vocabJson = './vocab.json';
offlineTtsPocketModelConfig.tokenScoresJson = './token_scores.json';
break;
case 6:
// KittenTTS
offlineTtsKittenModelConfig.model = './model.onnx';
offlineTtsKittenModelConfig.voices = './voices.bin';
offlineTtsKittenModelConfig.tokens = './tokens.txt';
offlineTtsKittenModelConfig.dataDir = './espeak-ng-data';
break;
}

const offlineTtsModelConfig = {
Expand Down
27 changes: 27 additions & 0 deletions wasm/tts/sync-tts-node.py
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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is recommended to specify the encoding (e.g., encoding="utf-8") when opening files to ensure consistent behavior across different platforms and locales.

Suggested change
with open(src) as f:
with open(src, encoding="utf-8") 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The re.sub call uses an excessively long line with escaped newlines, which violates PEP 8 line length guidelines and reduces readability. Refactoring the replacement string into a separate variable using concatenated strings or a multi-line string is more idiomatic. Additionally, the regex can be made more robust by allowing for variable whitespace between the export keyword and the opening brace.

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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is recommended to specify the encoding when opening the destination file for writing to maintain consistency.

Suggested change
with open(dst, "w") as f:
with open(dst, "w", encoding="utf-8") as f:

f.write(content)

print(f"Updated {dst} from {src}")