简体   繁体   English

如何在 Android 中获得等效的 Google Text-to-Speech 音调

[英]How to get equivalent Google Text-to-Speech pitch in Android

I "created" a custom Google TTS voice by setting a pitch and speech rate here .我通过在此处设置音调和语速“创建”自定义 Google TTS 语音。

The value I chose for pitch is negative (-6.4) and I want to use the exact values in my Android app.我为 pitch 选择的值为负 (-6.4),我想在我的 Android 应用程序中使用确切的值。

However, TextToSpeech.setPitch(float) cannot accept negative values.但是, TextToSpeech.setPitch(float)不能接受负值。 Here is the code from android.speech.tts.TextToSeech :这是来自android.speech.tts.TextToSeech的代码:

public int setPitch(float pitch) {
  if (pitch > 0.0f) {
    int intPitch = (int)(pitch * 100);
    if (intPitch > 0) {
      synchronized (mStartLock) {
        mParams.putInt(Engine.KEY_PARAM_PITCH, intPitch);
      }
      return SUCCESS;
    }
  }
  return ERROR;
}

I need some help determining the equivalent positive value that would be equivalent to -6.4.我需要一些帮助来确定相当于 -6.4 的等效正值。 It appears I cannot simply extrapolate the value using the relative scales [-20, 20] (default: 0) on the web interface and apparently [25, 400] (default: 100) from the Android library.看来我不能简单地使用 Web 界面上的相对比例 [-20, 20](默认值:0)和 Android 库中的 [25, 400](默认值:100)来简单地推断该值。 The latter obtained from com.android.settings.tts.TextToSpeechSettings , available here :后者从com.android.settings.tts.TextToSpeechSettings获得,可在此处获得

    /**
     * Speech pitch value. TTS pitch value varies from 25 to 400, where 100 is the value for normal
     * pitch. The max pitch value is set to 400, based on feedback from users and the GoogleTTS
     * pitch variation range. The range for pitch is not set in stone and should be readjusted based
     * on user need. This value should be kept in sync with the max value set in tts_settings xml.
     */
    private static final int MAX_SPEECH_PITCH = 400;
    private static final int MIN_SPEECH_PITCH = 25;

Thank you for your time.感谢您的时间。

I'm not sure how the default 0 (web interface) can equate to 100 (android library), but maybe this formula would work.我不确定默认的 0(网络界面)如何等于 100(android 库),但也许这个公式会起作用。

You can try using this formula:您可以尝试使用以下公式:

A_MIN_SPEECH_PITCH = -20; A_MIN_SPEECH_PITCH = -20;

A_MAX_SPEECH_PITCH = 20; A_MAX_SPEECH_PITCH = 20;

B_MIN_SPEECH_PITCH = 25; B_MIN_SPEECH_PITCH = 25;

B_MAX_SPEECH_PITCH = 400; B_MAX_SPEECH_PITCH = 400;

a_speech_pitch = // Desired pitch a_speech_pitch = // 所需的音调

b_speech_pitch = (B_MAX_SPEECH_PITCH - B_MIN_SPEECH_PITCH) * ((a_speech_pitch - A_MIN_SPEECH_PITCH) / (A_MAX_SPEECH_PITCH - A_MIN_SPEECH_PITCH)) + B_MIN_SPEECH_PITCH; b_speech_pitch = (B_MAX_SPEECH_PITCH - B_MIN_SPEECH_PITCH) * ((a_speech_pitch - A_MIN_SPEECH_PITCH) / (A_MAX_SPEECH_PITCH - A_MIN_SPEECH_PITCH)) + B_MIN_SPEECH_PITCH;

Test Case #1测试用例#1

a_speech_pitch = -20 a_speech_pitch = -20

b_speech_pitch = (400-25) * ((-20-(-20))/(20-(-20))) + 25 = 25 b_speech_pitch = (400-25) * ((-20-(-20))/(20-(-20))) + 25 = 25

Test Case #2测试用例#2

a_speech_pitch = 0 a_speech_pitch = 0

b_speech_pitch = (400-25) * ((0-(-20))/(20-(-20))) + 25 = 212.5 b_speech_pitch = (400-25) * ((0-(-20))/(20-(-20))) + 25 = 212.5

Test Case #3测试用例 #3

a_speech_pitch = 20 a_speech_pitch = 20

b_speech_pitch = (400-25) * ((20-(-20))/(20-(-20))) + 25 = 400 b_speech_pitch = (400-25) * ((20-(-20))/(20-(-20))) + 25 = 400

Test Case #4测试用例 #4

a_speech_pitch = -6.4 a_speech_pitch = -6.4

b_speech_pitch = (400-25) * ((-6.4-(-20))/(20-(-20))) + 25 = 152.5 b_speech_pitch = (400-25) * ((-6.4-(-20))/(20-(-20))) + 25 = 152.5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM