npm install itako-text-transformer-dictionary --save
specify instance as second argument of the Itako constructor as the value of the array.
<script src="https://npmcdn.com/itako"></script>
<script src="https://npmcdn.com/itako-text-reader-speech-synthesis"></script>
<script src="https://npmcdn.com/itako-audio-reader-audio-context"></script>
<script src="https://npmcdn.com/itako-text-transformer-dictionary"></script>
<script>
var textReader = new ItakoTextReaderSpeechSynthesis;
var audioReader = new ItakoAudioReaderAudioContext;
var transformer = new ItakoTextTransformerDictionary({
onMatch: function (define, originalToken, transformedToken, matches) {
// do staff...
// if return false, abort the transform.
},
});
var itako = new Itako([textReader, audioReader], [transformer], {
read: {
serial: true,
},
transformers: {
dictionary: {
options: [
// replace token.value to 'hello (pitch:2) world (pitch:0.5)'
{
pattern: 'greeting',
method: 'replace',
replacement: 'hello (pitch:2) world (pitch:0.5)',
},
// change token.options to $1:$2 (remove the matched value)
{
pattern: '/(volume|pitch):([\\.\\d]+)/',
method: 'toggle',
replacement: "{$1:'$2'}",
},
// create new token using properties instead of `nintendo`
{
pattern: 'nintendo',
method: 'exchange',
replacement: "{type:'audio',value:'http://static.edgy.black/fixture.wav'}",
},
// if match, overrides all tokens using new instance
{
pattern: '/play\\((.+?).wav\\)/',
method: 'rewrite',
replacement: "{type:'audio',value:'http://static.edgy.black/$1.wav'}",
},
// if match, passed arguments of transform to onMatch
{
pattern: '/@([\\S]+)/',
method: 'replace',
replacement: 'registered the `$1`',
},
],
},
},
});
// speech-synthesis say 'hello world, guys'. then play sound `fixture.wav`.
itako.read('greeting, guys. (pitch:0.75) nintendo');
// play sound `fixture.wav` only.
itako.read('play(fixture.wav)');
// say "registered the `59naga`"
itako.read('@59naga');
</script>
Requirement global
- NodeJS v5.10.0
- Npm v3.8.3
git clone https://github.com/itakojs/itako-text-transformer-dictionary
cd itako-text-transformer-dictionary
npm install
npm test