Skip to content

Honor system pitch and fix English sample in TTS settings#2

Merged
AliRezaTaleghani merged 1 commit into
mainfrom
feat/pitch-and-sample-fix
Jun 11, 2026
Merged

Honor system pitch and fix English sample in TTS settings#2
AliRezaTaleghani merged 1 commit into
mainfrom
feat/pitch-and-sample-fix

Conversation

@AliRezaTaleghani

Copy link
Copy Markdown
Contributor

Pitch (dsp/PitchShifter):

  • Add a duration-preserving SOLA pitch shifter (time-stretch + resample) so the Android system pitch setting is honored. The default path (factor ~1.0) returns audio untouched, so normal playback is unchanged and free.
  • Wire into AvaTtsService: when pitch != default, synthesize the sentence, shift, then write; otherwise keep the streaming path.
  • Fix an index overflow in the resampler on long buffers (compute position directly in double precision instead of accumulating, with a bound guard). Found on device (ArrayIndexOutOfBounds at ~63k samples, factor 0.87).

TTS settings sample (TtsDataCheckActivity):

  • GET_SAMPLE_TEXT now returns result code LANG_AVAILABLE instead of RESULT_OK. The settings screen only accepts the engine's sample when the code is LANG_AVAILABLE; with RESULT_OK it silently fell back to its built-in English string, which the Persian voice spoke as gibberish.

Diagnostics:

  • Log the request rate/pitch and a text preview in onSynthesizeText.

Verified on device (OnePlus Nord): "Play sample" now speaks Persian; pitch 0.79 applied with 65k frames delivered and no crash. Unit tests cover pitch up/down, duration preservation, and the large-buffer regression.

Pitch (dsp/PitchShifter):
- Add a duration-preserving SOLA pitch shifter (time-stretch + resample) so the
  Android system pitch setting is honored. The default path (factor ~1.0) returns
  audio untouched, so normal playback is unchanged and free.
- Wire into AvaTtsService: when pitch != default, synthesize the sentence, shift,
  then write; otherwise keep the streaming path.
- Fix an index overflow in the resampler on long buffers (compute position
  directly in double precision instead of accumulating, with a bound guard).
  Found on device (ArrayIndexOutOfBounds at ~63k samples, factor 0.87).

TTS settings sample (TtsDataCheckActivity):
- GET_SAMPLE_TEXT now returns result code LANG_AVAILABLE instead of RESULT_OK.
  The settings screen only accepts the engine's sample when the code is
  LANG_AVAILABLE; with RESULT_OK it silently fell back to its built-in English
  string, which the Persian voice spoke as gibberish.

Diagnostics:
- Log the request rate/pitch and a text preview in onSynthesizeText.

Verified on device (OnePlus Nord): "Play sample" now speaks Persian; pitch 0.79
applied with 65k frames delivered and no crash. Unit tests cover pitch up/down,
duration preservation, and the large-buffer regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@AliRezaTaleghani AliRezaTaleghani merged commit 239500a into main Jun 11, 2026
1 check passed
@AliRezaTaleghani AliRezaTaleghani deleted the feat/pitch-and-sample-fix branch June 11, 2026 22:33
@AliRezaTaleghani AliRezaTaleghani restored the feat/pitch-and-sample-fix branch June 11, 2026 22:40
AliRezaTaleghani added a commit that referenced this pull request Jun 11, 2026
Honor system pitch and fix English sample in TTS settings
@AliRezaTaleghani AliRezaTaleghani deleted the feat/pitch-and-sample-fix branch June 11, 2026 22:59
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.

1 participant