Lens Scripting API

    Class TextToSpeechModule

    Allows generation of audio from a given text with a variety of options.

    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);

    Hierarchy (View Summary, Expand)

    Index

    Constructors

    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 TextToSpeech.Options. 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 (TextToSpeech.WordInfo).

      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

      Returns void

    MMNEPVFCICPMFPCPTTAAATR