Skip to content

fix(tts): resolve options.voice_name in nemo_speech_tts_synthesize_tokens - #114

Open
sikso1892 wants to merge 1 commit into
NVIDIA:mainfrom
sikso1892:sikso1892/tts-tokens-voice-name
Open

sikso1892 wants to merge 1 commit into
NVIDIA:mainfrom
sikso1892:sikso1892/tts-tokens-voice-name

Conversation

@sikso1892

Copy link
Copy Markdown

Summary

Fixes #64.

nemo_speech_tts_synthesize_tokens ignored options.voice_name. With speaker < 0 and the voice given only by name, which tts.h allows ("voice_name — ignored when speaker >= 0"), every pre-tokenized request was spoken by the synthesizer's default speaker. nemo_speech_tts_synthesize_text resolved the name; the token call never received it.

  • Synthesizer::synthesize_tokens takes the voice name and resolves it with resolve_speaker(), the same rule prepare() uses. An empty name still gives the default speaker, so existing callers are unchanged.
  • nemo_speech_tts_synthesize_tokens passes voice_of(options).
  • No change to include/nemo_speech/tts.h; the new C++ parameter is trailing with a default.
  • An unknown or out-of-range voice_name now fails the token call with INVALID_ARGUMENT, as it already does for the text call.

language_code is not touched: the token path does not use it for synthesis.

Test

tts_c_smoke --tokens MAGPIE.gguf CODEC.gguf TOKENS [SPEAKER_INDEX]: with SPEAKER_INDEX, it synthesizes the tokens once with voice_name = SPEAKER_INDEX, speaker = -1 and once with speaker = SPEAKER_INDEX, both with seed = 1234, and fails if the PCM differs. It needs model files, so it is not registered with ctest.

CUDA build (cuda-tts preset, RTX PRO 5000, CUDA 13.5), magpie_tts_multilingual_357m.v2607.f16.gguf, 12 token IDs, SPEAKER_INDEX = 2:

build voice_name = "2", speaker = -1 speaker = 2 result
main (e790e46) 118784 bytes, f254e53bef2c7002 143360 bytes, 1b43b410c86a8b8c fails
this PR 143360 bytes, 1b43b410c86a8b8c 143360 bytes, 1b43b410c86a8b8c passes

The values are PCM byte counts and an FNV-1a hash of the PCM.

…kens

- nemo_speech_tts_synthesize_tokens ignored options.voice_name: with
  speaker < 0 the request was always spoken by the synthesizer's default
  speaker, while nemo_speech_tts_synthesize_text resolved the name
- Synthesizer::synthesize_tokens takes the voice name and resolves it the
  way prepare() does; an empty name still gives the default speaker
- tts_c_smoke --tokens takes an optional SPEAKER_INDEX and checks that
  voice_name and the speaker field give the same PCM

Fixes NVIDIA#64

Signed-off-by: moonsik.song <sikso1892@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Token-based speech synthesis can now use a requested voice name when no numeric speaker is specified. If no voice name is provided, synthesis continues to use the configured default voice. This makes voice selection available in token-based workflows while preserving the existing option to choose a speaker by number.

Token synthesis now uses the requested voice name when no numeric speaker is set. The C smoke test can compare PCM output from voice-name and numeric-speaker selection.

Changes: Token synthesis voice selection

Layer / File(s) Summary
Pass and resolve the voice name
src/tts/synthesizer.h, src/tts/synthesizer.cpp, src/tts/c_api.cpp
Synthesizer::synthesize_tokens accepts an optional voice name. The C API passes the requested name, and the synthesizer resolves it when the speaker value is negative.
Check voice-name and speaker output
tests/c/tts_c_smoke.c
The smoke test can synthesize the same tokens with a voice name and numeric speaker. It compares PCM byte counts and hashes.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to a493b

Token synthesis now honors the requested voice name when no numeric speaker is set, matching the text path. Unknown names now fail with an invalid-argument error. No merge-blocking risk was identified.

Security architecture risk: Low · up to a493b

Voice names now work for pre-tokenized synthesis. However, requests that select a numeric speaker still read the voice-name string even though callers were told it would be ignored. If that unused string is no longer readable, the synthesis call can terminate the calling process.

Retained concerns

  • Low · security · inferred: Token synthesis now reads the voice-name string before checking whether a numeric speaker was selected. The base did not read this field. As a result, a non-null but unreadable value in a documented ignored field can cause a process fault rather than a synthesis status.
Security review details

Security Blast Radius

  • inferred — The demonstrated exposure is at the native C call boundary. A fault there can interrupt other work in the same host process; remote control of the pointer is not established.

Trust Boundaries and Controls

  • observed — The wrapper checks the caller's declared options size before reading the field and handles null as empty. The numeric-speaker check controls whether the name is resolved, but runs after the wrapper has already read any supplied string.
Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Directly linked issue #64 asks that nemo_speech_tts_synthesize_tokens resolve options.voice_name when speaker < 0, matching the text call. The PR meets this requirement. src/tts/c_api.cpp now passes v…
Out of Scope Changes check Passed All changes support the objective of #64. The synthesizer.cpp and c_api.cpp hunks implement the name resolution for the token path. The new C++ parameter has a trailing default, so existing callers ar…
Full details: Linked Issues check

Explanation

Directly linked issue #64 asks that nemo_speech_tts_synthesize_tokens resolve options.voice_name when speaker < 0, matching the text call. The PR meets this requirement. src/tts/c_api.cpp now passes voice_of(options) to Synthesizer::synthesize_tokens. src/tts/synthesizer.cpp takes a voice_name argument and, when options.speaker < 0, sets the speaker from resolve_speaker(voice_name). An empty name yields impl_->default_speaker, which the constructor sets from default_voice_name when that name is set. This gives the same result as prepare(), which resolves the default voice name for an empty request name. Unknown or out-of-range names throw std::invalid_argument, which maps to INVALID_ARGUMENT. Numeric speaker values still bypass the name, as the header states. The issue's alternative (document the ignored name in tts.h) is not required, since the PR pursues the name-resolution outcome. Remaining uncertainty: the CUDA comparison results in the PR description are author-reported and model-dependent. They were not re-run, and no ctest covers this path. The issue does not require an automated test.

Full details: Out of Scope Changes check

Explanation

All changes support the objective of #64. The synthesizer.cpp and c_api.cpp hunks implement the name resolution for the token path. The new C++ parameter has a trailing default, so existing callers are unchanged and tts.h is not modified. The tests/c/tts_c_smoke.c changes add an opt-in model-dependent comparison of voice_name and numeric speaker output. This test directly exercises the fixed path. The raw summary also reports an FNV-1a hash initialization in the text-mode PCM sink of the same smoke test. This is a small test-harness change tied to the same comparison. No unrelated functional change was found in the inspected diffs of synthesizer.cpp and c_api.cpp. tests/c/tts_c_smoke.c was not diffed directly, so its content rests on the raw summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e790e46 and a493bf7.

Files selected for processing: 4

  • src/tts/c_api.cpp
  • src/tts/synthesizer.cpp
  • src/tts/synthesizer.h
  • tests/c/tts_c_smoke.c

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Recent review details

Context from checks skipped due to timeout: 2

  • GitHub Check: CodeRabbit
  • GitHub Check: Greptile Review
Additional context used

Path-based instructions: 1

Apply every section of REVIEW.md, in its priority order.

CodeRabbit configuration file

Files:

  • src/tts/c_api.cpp
  • src/tts/synthesizer.cpp
  • src/tts/synthesizer.h
  • tests/c/tts_c_smoke.c
ast-grep (0.51.3)

tests/c/tts_c_smoke.c

[warning] 181-181: Avoid atoi/atol/atoll/atof: they perform no error detection, returning 0 on non-numeric input and invoking undefined behavior on out-of-range values. This rule flags every use of these functions regardless of data provenance. Convert strings with strtol/strtoul/strtod and check errno (and the endptr) so malformed or overflowing input is rejected.
Context: atoi(argv[5])
Note: [CWE-20] Improper Input Validation.

(atoi-no-error-detection-c)

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Fixes voice selection for pre-tokenized TTS requests.

  • Pre-tokenized speech requests use the named speaker when no index is set.

No actionable issues found. Review was based on source inspection; model-backed tests were not run.

Reviews (1) · Last reviewed commit: "fix(tts): resolve options.voice_name in ..." · Reviewed by Greptile

This branch has not been deployed

No deployments
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.

nemo_speech_tts_synthesize_tokens ignores options.voice_name: every pre-tokenized request is spoken by the default speaker

1 participant