We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

MLTtsConfig

com.huawei.hms.mlsdk.tts.MLTtsConfig

Configures TTS.

Sample Code

  1. // 1. Create parameters. These parameters are optional. If you do not set them, default values are used.
  2. MLTtsConfig mlTtsConfig = new MLTtsConfig()
  3.    .setVolume(1.5f)
  4.    .setSpeed(1.5f)
  5.    .setLanguage(MLTtsConstants.TTS_ZH_HANS)
  6.    .setPerson(MLTtsConstants.TTS_SPEAKER_FEMALE_ZH);
  7. // 2. View custom parameter values.
  8.    mlTtsConfig.getLanguage();// Obtain the language. If null is returned, the value is not customized.
  9.    mlTtsConfig.getPerson();// Obtain the speaker name. If null is returned, the value is not customized.
  10.    mlTtsConfig.getSpeed();// Obtain the speed. If 0 is returned, the value is not customized.
  11.    mlTtsConfig.getVolume();// Obtain the volume. If 0 is returned, the value is not customized.
  12. // 3. Update configurations.
  13.    // a. Use the previous configurations if there is no custom configuration. Use default configurations if no previous configuration exists.
  14.    // b. Use current custom configurations if there are any.
  15. // 4. Update mode:
  16. // a. During initialization.
  17.    MLTtsEngine mlTtsEngine =  = new MLTtsEngine(mlTtsConfig);
  18. // b. During the process.
  19.    mlTtsEngine.updateConfig(mlTtsConfig);

Public Constructor Summary

Constructor name
MLTtsConfig()

Public Method Summary

Return typeMethod name
StringgetLanguage()
StringgetPerson()
floatgetSpeed()
floatgetVolume()
MLTtsConfigsetLanguage(String language)
MLTtsConfigsetPerson(String person)
MLTtsConfigsetSpeed(float speed)
MLTtsConfigsetVolume(float volume)

Public Constructors

Method
public MLTtsConfig()
Constructor.

Public Methods

Method
public String getLanguage()
Obtains the language in the current configuration instance.

Return

Typedesc
String

Returns the language. If null is returned, the value is not customized.

Method
public String getPerson()
Obtains the speaker in the current configuration instance.

Return

Typedesc
String

Returns the speaker name. If null is returned, the value is not customized.

Method

public float getSpeed()

Obtains the speech speed in the current configuration instance.

Return

Typedesc
float

Returns the speech speed. If 0 is returned, the value is not customized.

Method

public float getVolume()

Obtains the volume in the current configuration instance.

Return

Typedesc
floatReturns the volume. If 0 is returned, the value is not customized.
Method

public MLTtsConfig setLanguage(String language)

Sets the language.

Parameters

Parameter nameParameter desc
language

Language name. If this parameter is not set, the default value zh-Hans is used, indicating Simplified Chinese.

TTS_EN_US: English (US)

TTS_ZH_HANS: Simplified Chinese

TTS_LAN_ES_ES: Spanish

TTS_LAN_FR_FR: French

Return

Typedesc
MLTtsConfigConfiguration instance after the language is set.
Method

public MLTtsConfig setPerson(String person)

Sets the speaker.

Parameters

Parameter nameParameter desc
person

Name of the speaker. If this parameter is not set, the default value Female-zh is used, indicating Chinese female voice.

TTS_SPEAKER_FEMALE_EN: English female voice

TTS_SPEAKER_FEMALE_ZH: Chinese female voice

TTS_SPEAKER_MALE_EN: English male voice

TTS_SPEAKER_MALE_ZH: Chinese male voice

TTS_SPEAKER_FEMALE_ES: Spanish standard female voice

TTS_SPEAKER_FEMALE_FR: French standard female voice

Return

Typedesc
MLTtsConfigConfiguration instance after the speaker is set.
Method

public MLTtsConfig setSpeed(float speed)

Sets the speech speed.

Parameters

Parameter nameParameter desc
speed

Speech speed. The value range is (0, 2). Value 1.0 indicates the normal speed. A value less than 1.0 indicates a lower speed. Value 0.5 indicates half of the normal speed. If the value is greater than 1.0, the speed is accelerated. For example, 1.5 indicates that the speed is 1.5 times the normal speed. If this parameter is not set, the default value is 1.0 is used.

Return

Typedesc
MLTtsConfigConfiguration instance after the speech speed is set.
Method

public MLTtsConfig setVolume(float volume)

Sets the volume.

Parameters

Parameter nameParameter desc
volume

Speech volume. The value range is (0, 2). Value 1.0 indicates the normal volume. A value less than 1.0 indicates a lower volume. Value 0.5 indicates half of the normal volume. If the value is greater than 1.0, the volume increases. For example, 1.5 indicates that the volume is 1.5 times the normal volume. If this parameter is not set, the default value is 1.0 is used.

Return

Typedesc
MLTtsConfigConfiguration instance after the volume is set.
This page may contain third-party content. For details, click here.
Search
Enter a keyword.