Skip to content

Add C API for KittenTTS - #2467

Merged
csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:c-api-kitten
Aug 8, 2025
Merged

csukuangfj merged 2 commits into
k2-fsa:masterfrom
csukuangfj:c-api-kitten

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Aug 8, 2025 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added support for the Kitten English text-to-speech (TTS) model in the C API.
    • Introduced a new example demonstrating how to synthesize English speech using the Kitten TTS model and save the output as a WAV file.
    • Enhanced the build system and automated workflows to compile, test, and upload generated audio artifacts for the new TTS example.
  • Bug Fixes
    • Fixed duplicated word typos in debug print statements across multiple TTS example programs.

@csukuangfj
csukuangfj requested a review from Copilot August 8, 2025 07:12
@coderabbitai

coderabbitai Bot commented Aug 8, 2025 •

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Caution

Review failed

The pull request is closed.

Walkthrough

A new example for English text-to-speech (TTS) using the Kitten model was introduced to the C API, including a demonstration C file, CMake integration, and workflow automation for building and testing. The C API and its configuration structures were updated to support Kitten TTS models, with corresponding internal logic and public struct changes.

Changes

Cohort / File(s) Change Summary
C API Kitten TTS Structs & Internal Support
sherpa-onnx/c-api/c-api.h, sherpa-onnx/c-api/c-api.cc
Added a new struct for Kitten TTS model configuration to the public C API header and updated the internal function to handle Kitten model fields in the TTS config.
Kitten TTS Example & Build Integration
c-api-examples/kitten-tts-en-c-api.c, c-api-examples/CMakeLists.txt
Added a C example demonstrating Kitten TTS usage, and updated CMake to build the new example when TTS is enabled.
CI Workflow for Kitten TTS Example
.github/workflows/c-api.yaml
Added a workflow step to build, test, and upload output for the Kitten TTS C API example, including model download, environment setup, execution, and artifact upload.
Debug Print Statement Fixes
c-api-examples/kokoro-tts-en-c-api.c, c-api-examples/kokoro-tts-zh-en-c-api.c, c-api-examples/matcha-tts-en-c-api.c, c-api-examples/matcha-tts-zh-c-api.c, c-api-examples/offline-tts-c-api.c
Corrected duplicated word "is" in debug print statements related to speaker ID output in multiple example files.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant KittenTTS_C_Example
    participant SherpaOnnxCAPI
    participant KittenModelFiles

    User->>KittenTTS_C_Example: Run main()
    KittenTTS_C_Example->>KittenModelFiles: Load model, voices, tokens
    KittenTTS_C_Example->>SherpaOnnxCAPI: Initialize TTS config (Kitten)
    KittenTTS_C_Example->>SherpaOnnxCAPI: Synthesize text to audio
    SherpaOnnxCAPI-->>KittenTTS_C_Example: Return generated audio
    KittenTTS_C_Example->>User: Write WAV file, print info
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Poem

In the meadow of code where the kittens now speak,
A new TTS purrs with a soft, clever tweak.
Structs and configs, all tidy and neat,
The build runs, the tests pass, the voices sound sweet.
With every new feature, we hop with delight—
Kitten TTS sings through the C API night!
🐇🎶


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aad2d21 and 6cc4adc.

📒 Files selected for processing (6)
  • c-api-examples/kitten-tts-en-c-api.c (1 hunks)
  • c-api-examples/kokoro-tts-en-c-api.c (1 hunks)
  • c-api-examples/kokoro-tts-zh-en-c-api.c (1 hunks)
  • c-api-examples/matcha-tts-en-c-api.c (1 hunks)
  • c-api-examples/matcha-tts-zh-c-api.c (1 hunks)
  • c-api-examples/offline-tts-c-api.c (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds C API support for KittenTTS, a text-to-speech engine, to the sherpa-onnx library. The changes enable users to use KittenTTS models through the existing C API interface.

  • Adds SherpaOnnxOfflineTtsKittenModelConfig struct to configure KittenTTS models
  • Integrates Kitten configuration into the existing TTS model configuration structure
  • Provides a complete example demonstrating KittenTTS usage with English text-to-speech

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sherpa-onnx/c-api/c-api.h Defines the KittenTTS configuration structure and integrates it into the main TTS model config
sherpa-onnx/c-api/c-api.cc Implements configuration mapping from C API structs to internal C++ configuration
c-api-examples/kitten-tts-en-c-api.c Provides a complete example showing how to use KittenTTS for English text-to-speech
c-api-examples/CMakeLists.txt Adds build configuration for the KittenTTS example
.github/workflows/c-api.yaml Adds CI testing for the KittenTTS functionality

tts_config.model.kitten.data_dir =
SHERPA_ONNX_OR(config->model.kitten.data_dir, "");
tts_config.model.kitten.length_scale =
SHERPA_ONNX_OR(config->model.kitten.length_scale, 1.0);

Copilot AI Aug 8, 2025

Copy link

Choose a reason for hiding this comment

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

The SHERPA_ONNX_OR macro is being used with a float value (1.0) as the default, but this macro appears to be designed for pointer/string checks based on its usage with string fields above. This may not work correctly for float values and could cause compilation errors or unexpected behavior.

Suggested change
SHERPA_ONNX_OR(config->model.kitten.length_scale, 1.0);
(config->model.kitten.length_scale != 0.0 ? config->model.kitten.length_scale : 1.0);

Copilot uses AI. Check for mistakes.
Comment thread c-api-examples/kitten-tts-en-c-api.c Outdated
@csukuangfj
csukuangfj merged commit f0ff58f into k2-fsa:master Aug 8, 2025
@csukuangfj
csukuangfj deleted the c-api-kitten branch August 8, 2025 07:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
c-api-examples/kitten-tts-en-c-api.c (1)

61-62: Clarify speed vs length_scale semantics

Header docs say smaller length_scale => faster. The example’s comment says larger speed => faster. If speed is internally mapped as 1/length_scale, consider adding a short note to prevent confusion (done in the diff above).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9122c9d and aad2d21.

📒 Files selected for processing (5)
  • .github/workflows/c-api.yaml (1 hunks)
  • c-api-examples/CMakeLists.txt (1 hunks)
  • c-api-examples/kitten-tts-en-c-api.c (1 hunks)
  • sherpa-onnx/c-api/c-api.cc (1 hunks)
  • sherpa-onnx/c-api/c-api.h (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-06T04:23:50.237Z
Learnt from: litongjava
PR: k2-fsa/sherpa-onnx#2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:23:50.237Z
Learning: The sherpa-onnx JNI library files are stored in Hugging Face repository at https://huggingface.co/csukuangfj/sherpa-onnx-libs under versioned directories like jni/1.12.7/, and the actual Windows JNI library filename is "sherpa-onnx-jni.dll" as defined in Core.java constants.

Applied to files:

  • sherpa-onnx/c-api/c-api.h
  • c-api-examples/CMakeLists.txt
📚 Learning: 2025-08-06T04:18:47.981Z
Learnt from: litongjava
PR: k2-fsa/sherpa-onnx#2440
File: sherpa-onnx/java-api/src/main/java/com/k2fsa/sherpa/onnx/core/Core.java:4-6
Timestamp: 2025-08-06T04:18:47.981Z
Learning: In sherpa-onnx Java API, the native library names in Core.java (WIN_NATIVE_LIBRARY_NAME = "sherpa-onnx-jni.dll", UNIX_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.so", MACOS_NATIVE_LIBRARY_NAME = "libsherpa-onnx-jni.dylib") are copied directly from the compiled binary filenames and should not be changed to match other libraries' naming conventions.

Applied to files:

  • sherpa-onnx/c-api/c-api.h
  • c-api-examples/CMakeLists.txt
🔇 Additional comments (5)
c-api-examples/CMakeLists.txt (2)

26-28: LGTM: New Kitten TTS example target is correctly gated and linked

  • Target is added under SHERPA_ONNX_ENABLE_TTS, consistent with other TTS examples.
  • Linking against sherpa-onnx-c-api matches matcha/kokoro examples (no cargs unless the example uses it).

26-28: Verification complete: example file and dependencies are correctly configured

All checks passed:

  • c-api-examples/kitten-tts-en-c-api.c exists.
  • .github/workflows/c-api.yaml references kitten-tts-en-c-api.
  • No CLI parsing in the example; linking without cargs is appropriate.

No changes required.

sherpa-onnx/c-api/c-api.cc (2)

1210-1221: LGTM: Kitten TTS config mapped with sane defaults and parity with other models

  • Fields (model, voices, tokens, data_dir, length_scale) are wired via SHERPA_ONNX_OR with consistent defaults (length_scale=1.0).
  • Placement aligns with existing blocks (vits/matcha/kokoro). No obvious regressions.

1210-1221: Kitten TTS integration points are properly wired up

All requested checks pass without issue:

  • The C-API header (c-api/c-api.h) defines SherpaOnnxOfflineTtsKittenModelConfig and embeds it as the kitten field in SherpaOnnxOfflineTtsModelConfig.
  • The offline-TTS implementation (csrc/offline-tts-impl.cc) includes offline-tts-kitten-impl.h and branches on config.model.kitten.model.
  • OfflineTtsKittenModelConfig::Validate() and ToString() are called in csrc/offline-tts-model-config.cc (lines 46 and 61).
  • OfflineTtsConfig::Validate() and ToString() in csrc/offline-tts.cc handle the kitten model.
  • The loader and runtime for model.kitten are implemented in offline-tts-kitten-model.cc/.h.

No further action required.

sherpa-onnx/c-api/c-api.h (1)

1051-1051: Struct growth and ABI considerations

Appending kitten at the end of SherpaOnnxOfflineTtsModelConfig is the least risky option for source compatibility. For runtime ABI compatibility, ensure clients recompile against this header before using a newer shared library; otherwise, the callee may read beyond the caller-allocated struct.

  • If this is intended as a minor version bump, please reflect it in release notes. The workflow already runs ./new-release.sh.

Comment on lines +88 to +122
- name: Test KittenTTS
shell: bash
run: |
name=kitten-tts-en-c-api
gcc -o $name ./c-api-examples/$name.c \
-I ./build/install/include \
-L ./build/install/lib/ \
-l sherpa-onnx-c-api \
-l onnxruntime

ls -lh $name

if [[ ${{ matrix.os }} == ubuntu-latest || ${{ matrix.os }} == ubuntu-22.04-arm ]]; then
ldd ./$name
echo "----"
readelf -d ./$name
fi

curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kitten-nano-en-v0_1-fp16.tar.bz2
tar xf kitten-nano-en-v0_1-fp16.tar.bz2
rm kitten-nano-en-v0_1-fp16.tar.bz2

export LD_LIBRARY_PATH=$PWD/build/install/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$PWD/build/install/lib:$DYLD_LIBRARY_PATH

./$name

rm $name
rm -rf kitten-nano-en-v0_1-fp16

- uses: actions/upload-artifact@v4
with:
name: kitten-tts-wavs-${{ matrix.os }}
path: ./generated-kitten-en.wav

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

❓ Verification inconclusive

Harden the KittenTTS CI step (fail fast, robust downloads, rpath, artifact existence)

  • Add set -euo pipefail so failures propagate.
  • Use curl -fSL to fail on HTTP errors.
  • Optionally embed rpath so LD/DYLD_LIBRARY_PATH isn’t required.
  • Verify the WAV exists before uploading.

Apply this diff within the step:

       - name: Test KittenTTS
         shell: bash
         run: |
-          name=kitten-tts-en-c-api
+          set -euo pipefail
+          name=kitten-tts-en-c-api
           gcc -o $name ./c-api-examples/$name.c \
             -I ./build/install/include \
             -L ./build/install/lib/ \
-            -l sherpa-onnx-c-api \
-            -l onnxruntime
+            -l sherpa-onnx-c-api \
+            -l onnxruntime \
+            -Wl,-rpath,'$ORIGIN/build/install/lib'
 
           ls -lh $name
 
           if [[ ${{ matrix.os }} == ubuntu-latest || ${{ matrix.os }} == ubuntu-22.04-arm ]]; then
             ldd ./$name
             echo "----"
             readelf -d ./$name
           fi
 
-          curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kitten-nano-en-v0_1-fp16.tar.bz2
+          curl -fSL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kitten-nano-en-v0_1-fp16.tar.bz2
           tar xf kitten-nano-en-v0_1-fp16.tar.bz2
           rm kitten-nano-en-v0_1-fp16.tar.bz2
 
           export LD_LIBRARY_PATH=$PWD/build/install/lib:$LD_LIBRARY_PATH
           export DYLD_LIBRARY_PATH=$PWD/build/install/lib:$DYLD_LIBRARY_PATH
 
           ./$name
+          test -f generated-kitten-en.wav
 
           rm $name
           rm -rf kitten-nano-en-v0_1-fp16

Note: If macOS fails due to $ORIGIN, replace it with @loader_path in the rpath flag for Darwin.


Harden the “Test KittenTTS” Bash step

Introduce early‐exit, strict shell flags, robust download checks, embedded rpath, and artifact validation:

  • Prepend set -euo pipefail at the top of the run: block to fail fast on any error or unset variable.
  • Switch curl -SL to curl -fSL so HTTP errors abort the script.
  • Add -Wl,-rpath,'$ORIGIN/build/install/lib' to the gcc command line (use @loader_path on macOS) to avoid relying on LD_LIBRARY_PATH/DYLD_LIBRARY_PATH.
  • After running the binary, verify the WAV was actually created with test -f generated-kitten-en.wav before uploading.
   - name: Test KittenTTS
     shell: bash
     run: |
+      set -euo pipefail
       name=kitten-tts-en-c-api
       gcc -o $name ./c-api-examples/$name.c \
         -I ./build/install/include \
         -L ./build/install/lib/ \
-        -l sherpa-onnx-c-api \
-        -l onnxruntime
+        -l sherpa-onnx-c-api \
+        -l onnxruntime \
+        -Wl,-rpath,'$ORIGIN/build/install/lib'

       ls -lh $name

       if [[ ${{ matrix.os }} == ubuntu-latest || ${{ matrix.os }} == ubuntu-22.04-arm ]]; then
         ldd ./$name
         echo "----"
         readelf -d ./$name
       fi

-      curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kitten-nano-en-v0_1-fp16.tar.bz2
+      curl -fSL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kitten-nano-en-v0_1-fp16.tar.bz2
       tar xf kitten-nano-en-v0_1-fp16.tar.bz2
       rm kitten-nano-en-v0_1-fp16.tar.bz2

       export LD_LIBRARY_PATH=$PWD/build/install/lib:$LD_LIBRARY_PATH
       export DYLD_LIBRARY_PATH=$PWD/build/install/lib:$DYLD_LIBRARY_PATH

       ./$name
+      test -f generated-kitten-en.wav

       rm $name
       rm -rf kitten-nano-en-v0_1-fp16

Note: On Darwin replace $ORIGIN with @loader_path in the rpath flag.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Test KittenTTS
shell: bash
run: |
name=kitten-tts-en-c-api
gcc -o $name ./c-api-examples/$name.c \
-I ./build/install/include \
-L ./build/install/lib/ \
-l sherpa-onnx-c-api \
-l onnxruntime
ls -lh $name
if [[ ${{ matrix.os }} == ubuntu-latest || ${{ matrix.os }} == ubuntu-22.04-arm ]]; then
ldd ./$name
echo "----"
readelf -d ./$name
fi
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kitten-nano-en-v0_1-fp16.tar.bz2
tar xf kitten-nano-en-v0_1-fp16.tar.bz2
rm kitten-nano-en-v0_1-fp16.tar.bz2
export LD_LIBRARY_PATH=$PWD/build/install/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$PWD/build/install/lib:$DYLD_LIBRARY_PATH
./$name
rm $name
rm -rf kitten-nano-en-v0_1-fp16
- uses: actions/upload-artifact@v4
with:
name: kitten-tts-wavs-${{ matrix.os }}
path: ./generated-kitten-en.wav
- name: Test KittenTTS
shell: bash
run: |
set -euo pipefail
name=kitten-tts-en-c-api
gcc -o $name ./c-api-examples/$name.c \
-I ./build/install/include \
-L ./build/install/lib/ \
-l sherpa-onnx-c-api \
-l onnxruntime \
-Wl,-rpath,'$ORIGIN/build/install/lib'
ls -lh $name
if [[ ${{ matrix.os }} == ubuntu-latest || ${{ matrix.os }} == ubuntu-22.04-arm ]]; then
ldd ./$name
echo "----"
readelf -d ./$name
fi
curl -fSL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kitten-nano-en-v0_1-fp16.tar.bz2
tar xf kitten-nano-en-v0_1-fp16.tar.bz2
rm kitten-nano-en-v0_1-fp16.tar.bz2
export LD_LIBRARY_PATH=$PWD/build/install/lib:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$PWD/build/install/lib:$DYLD_LIBRARY_PATH
./$name
test -f generated-kitten-en.wav
rm $name
rm -rf kitten-nano-en-v0_1-fp16
- uses: actions/upload-artifact@v4
with:
name: kitten-tts-wavs-${{ matrix.os }}
path: ./generated-kitten-en.wav
🤖 Prompt for AI Agents
In .github/workflows/c-api.yaml between lines 88 and 122, enhance the "Test
KittenTTS" bash step by adding `set -euo pipefail` at the start of the run block
to enable strict error handling and fail fast on unset variables. Modify the
curl command to use `curl -fSL` to ensure HTTP errors cause the script to abort.
Update the gcc command to include the rpath linker flag: use
`-Wl,-rpath,'$ORIGIN/build/install/lib'` on Linux and
`-Wl,-rpath,@loader_path/build/install/lib` on macOS to embed the library path
and avoid relying on environment variables. Finally, after executing the binary,
add a check with `test -f generated-kitten-en.wav` to confirm the WAV file was
created before uploading the artifact.

Comment thread c-api-examples/kitten-tts-en-c-api.c
Comment thread sherpa-onnx/c-api/c-api.h
Comment on lines +1035 to +1043
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsKittenModelConfig {
const char *model;
const char *voices;
const char *tokens;
const char *data_dir;

float length_scale; // < 1, faster in speech speed; > 1, slower in speed
} SherpaOnnxOfflineTtsKittenModelConfig;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Document required/optional fields and clarify defaults for Kitten config

  • Please add brief docs mirroring other TTS structs: which files are required (model/voices/tokens/data_dir) and whether length_scale has a default (e.g., 1.0 when 0 or unset).
  • The example leaves length_scale unset (0 after memset). If c-api.cc defaults it to 1.0, note that here to avoid confusion.

To confirm default handling in the implementation:


🏁 Script executed:

#!/bin/bash
# Verify kitten config handling and defaults in the implementation
rg -n "GetOfflineTtsConfig|Kitten|kitten" -A 10 -B 10 sherpa-onnx | sed -n '1,200p'

Length of output: 14951


🏁 Script executed:

#!/bin/bash
# Locate and inspect the C++ core kitten model config implementation
echo "C++ core kitten model config files:"
fd -HI -g 'offline-tts-kitten-model-config.*'
for f in $(fd -HI -g 'offline-tts-kitten-model-config.*'); do
  echo "=== $f ==="
  sed -n '1,100p' "$f"
done

Length of output: 6864


🏁 Script executed:

#!/bin/bash
# Inspect C API conversion for Kitten TTS config defaults
echo "Searching for C API struct definition and conversion usage..."
rg -n "SherpaOnnxOfflineTtsKittenModelConfig" -A5 -B5 sherpa-onnx/c-api
echo ""
echo "Searching where Kitten config is mapped to C++ core struct..."
rg -n "kitten" -A10 -B5 sherpa-onnx/c-api

Length of output: 5030


Add documentation for Kitten TTS config fields and clarify defaults
Please update sherpa-onnx/c-api/c-api.h to mirror the style of the existing TTS structs (VITS, Matcha, Kokoro) by annotating which fields are required and what defaults apply:

• In typedef struct SherpaOnnxOfflineTtsKittenModelConfig { … }:
– const char *model;
‣ Path to the kitten ONNX model. Required.
– const char *voices;
‣ Path to voices.bin for kitten. Required.
– const char *tokens;
‣ Path to tokens.txt for kitten. Required.
– const char *data_dir;
‣ Directory containing espeak-ng files (phontab, phonindex, etc.). Required.
– float length_scale; // <1 faster; >1 slower
‣ Inverse of speech speed. Optional. Defaults to 1.0 if zero or unset (as enforced by the C++ core and in the C API mapping via SHERPA_ONNX_OR(..., 1.0)).

• In SherpaOnnxOfflineTtsModelConfig, you can leave the kitten member where it is (added at the end), but ensure consumers know this is a new field and may affect ABI compatibility.

Refer to the comment blocks on SherpaOnnxOfflineTtsOfflineTtsMatchaModelConfig and SherpaOnnxOfflineTtsKokoroModelConfig for examples of how required/optional fields and defaults are documented.

🤖 Prompt for AI Agents
In sherpa-onnx/c-api/c-api.h around lines 1035 to 1043, add detailed comments to
each field of SherpaOnnxOfflineTtsKittenModelConfig to specify which are
required and which are optional with defaults, following the style used in
SherpaOnnxOfflineTtsMatchaModelConfig and SherpaOnnxOfflineTtsKokoroModelConfig.
Document that model, voices, tokens, and data_dir are required paths, and
length_scale is optional with a default of 1.0 if unset or zero. Also, in
SherpaOnnxOfflineTtsModelConfig, keep the kitten member at the end but add a
note that this is a new field that may impact ABI compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants