Allows generation of speech from a given text. You can use only one TextToSpeechModule in a Lens. However, its methods can be called multiple times in parallel if needed.

//@input Asset.TextToSpeechModule textToSpeech

var onTTSErrorHandler = function(error, description){
print('error: ' + error + " desc: " + description);
}

var onTTSCompleteHandler = function(audioTrackAsset, wordInfos){
var additionalInformation = "Successfully synthesized audio\n\n";
var wordInfosTxt = "Word Infos:";
for (var i = 0; i < wordInfos.length; i++) {
wordInfosTxt += "\nWord: '" + wordInfos[i].word + "', startTime: " + wordInfos[i].startTime.toString() + ", endTime: " + wordInfos[i].endTime.toString();
}
print(additionalInformation + wordInfosTxt);
var audioComponent = script.getSceneObject().createComponent('Component.AudioComponent');
audioComponent.audioTrack = audioTrackAsset;
audioComponent.play(1);
}

script.textToSpeech.synthesize("show me you love cats, without telling me you love cats!" , TextToSpeech.Options.create(), onTTSCompleteHandler, onTTSErrorHandler);
interface TextToSpeechModule {
    name: string;
    uniqueIdentifier: string;
    getTypeName(): string;
    isOfType(type: string): boolean;
    isSame(other: ScriptObject): boolean;
    synthesize(input: string, options: TextToSpeech.Options, onTTSComplete: ((audioTrackAsset: AudioTrackAsset, wordInfo: WordInfo[], phonemeInfo: PhonemeInfo[], voiceStyle: any) => void), onTTSError: ((error: number, description: string) => void)): void;
}

Hierarchy (view full)

Properties

name: string

The name of the Asset in Lens Studio.

uniqueIdentifier: string

Methods

  • Returns the name of this object's type.

    Returns string

  • Returns true if the object matches or derives from the passed in type.

    Parameters

    • type: string

    Returns boolean

  • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

    Parameters

    Returns boolean

  • Generates speech (AudioTrackAsset) of a given text. Input should be the text to synthesize (Currently supports text in English only. Non English characters will be stripped). Options should be a TextToSpeechOptions. onTTsComplete should be a callback function which will be called once the audio generation is completed. The callback will receive two parameters: the generated audio file (AudioTrackAsset) and maps of word/timing (WordInfos). onTTSError should be a callback function which will be called if there is an error. This callback will receive a message of the error code and its description.

    Parameters

    • input: string
    • options: TextToSpeech.Options
    • onTTSComplete: ((audioTrackAsset: AudioTrackAsset, wordInfo: WordInfo[], phonemeInfo: PhonemeInfo[], voiceStyle: any) => void)
        • (audioTrackAsset, wordInfo, phonemeInfo, voiceStyle): void
        • Parameters

          Returns void

    • onTTSError: ((error: number, description: string) => void)
        • (error, description): void
        • Parameters

          • error: number
          • description: string

          Returns void

    Returns void