Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 256 lines (153 sloc) 6.44 KB

Utterance Titanium

Utterance lets you use Text to Speech in your Titanium projects. This uses iOS7's Speech Synthesizer when on iOS and android.speech.tts.TextToSpeech on Android.

Importing the module using require


var utterance = require('bencoding.utterance');

Working with the Speech Proxy

The Speech proxy provides access to the platform's native Text To Speech Engine. A new instance of this is created when you call createSpeech.

Example



var speech = utterance.createSpeech();

startSpeaking

The startSpeaking method will begin to speak the text provided.

Parameters

The startSpeaking method, takes a dictionary as a parameter with the following fields:

text : String :Required

The text to be spoken

voice : String :Optional

The voice to be used in speaking. If this parameter is not defined, the proper language will be inferred on iOS. On Android, the default language of the device will be used.

rate : float :Optional

The speed which the text will be read. This is a value between 0 and 1. You can use the DEFAULT_SPEECH_RATE, MIN_SPEECH_RATE, and MAX_SPEECH_RATE properties as well.

volume : float :Optional - iOS only

The volume of the reader. This is a value between 0 and 1. By default a value of 1 will be used.

preUtteranceDelay : float :Optional - iOS only

This places a delay at the beginning of the utterance.

postUtteranceDelay : float :Optional - iOS only

This places a delay at the end of the utterance.

pitch : float :Optional - Android only

This method sets the speech pitch for the TextToSpeech engine.

Example


	if(speech.isSpeaking){
		Ti.API.info("already speaking");
	}
	
	speech.startSpeaking({
		text:"こんにちは"
	});	

continueSpeaking

This method continues reading any speech that has been paused.

Parameters

None

Example


	if(speech.isSpeaking){
		Ti.API.info("Already speaking, nothing to continue");
		return;
	}	
	speech.continueSpeaking();	

pauseSpeaking

This method pauses the speaker. This method has an optional parameter that allows you to pause immediately or at the end of a word. By default this method will pause immediately.

Example - Without optional parameter


	
	speech.pauseSpeaking();

Example - Optional parameter pause immediate


	
	speech.pauseSpeaking(speech.SPEECH_BOUNDARY_IMMEDIATE);

Example - Without optional parameter pause at end of word


	
	speech.pauseSpeaking(speech.SPEECH_BOUNDARY_WORD);

stopSpeaking

This method stops the speaker. This method has an optional parameter that allows you to pause immediately or at the end of a word. By default this method will stop immediately.

Example - Without optional parameter


	
	speech.stopSpeaking();

Example - Optional parameter pause immediate


	
	speech.stopSpeaking(speech.SPEECH_BOUNDARY_IMMEDIATE);

Example - Without optional parameter pause at end of word


	
	speech.stopSpeaking(speech.SPEECH_BOUNDARY_WORD);

Properties

DEFAULT_SPEECH_RATE

This property can be used when setting the rate value for the startSpeaking method. This defaults the rate to the current device/system value.

MIN_SPEECH_RATE

This property can be used when setting the rate value for the startSpeaking method. This value is the slowest reading rate the device supports.

MAX_SPEECH_RATE

This property can be used when setting the rate value for the startSpeaking method. This value is the fastest reading rate the device supports.

SPEECH_BOUNDARY_IMMEDIATE

This property can be used when calling the stopSpeaking or pauseSpeaking methods. This will pause or stop the speaker immediately. This is the default configuration if no parameters are provided for the stopSpeaking or pauseSpeaking methods.

SPEECH_BOUNDARY_WORD

This property can be used when calling the stopSpeaking or pauseSpeaking methods. This will pause or stop the speaker after the current word.

Events

started

This event is fired once the speaker has started reading the text.

Example



var utterance = require('bencoding.utterance'),
	speech = utterance.createSpeech();

speech.addEventListener('started',function(d){
	Ti.API.info(JSON.stringify(d));
});

completed

This event is fired once the speaker has finished reading the text.

Example



var utterance = require('bencoding.utterance'),
	speech = utterance.createSpeech();

speech.addEventListener('completed',function(d){
	Ti.API.info(JSON.stringify(d));
});

paused

This event is fired once the speaker has been paused.

Example



var utterance = require('bencoding.utterance'),
	speech = utterance.createSpeech();

speech.addEventListener('paused',function(d){
	Ti.API.info(JSON.stringify(d));
});

canceled

This event is fired once the speaker has been canceled.

Example



var utterance = require('bencoding.utterance'),
	speech = utterance.createSpeech();

speech.addEventListener('canceled',function(d){
	Ti.API.info(JSON.stringify(d));
});

continued

This event is fired once the speaker has been continued.

Example



var utterance = require('bencoding.utterance'),
	speech = utterance.createSpeech();

speech.addEventListener('continued',function(d){
	Ti.API.info(JSON.stringify(d));
});

License

Utterance is available under the Apache 2.0 license.

Copyright 2014 Benjamin Bahrenburg

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.