-
Notifications
You must be signed in to change notification settings - Fork 0
/
texttospeech.v2.js
executable file
·58 lines (51 loc) · 1.32 KB
/
texttospeech.v2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const TextToSpeechV1 = require('watson-developer-cloud/text-to-speech/v1');
const fs = require('fs');
var contents = fs.readFileSync('DATA.txt', 'utf8');
const textToSpeech = new TextToSpeechV1(
{
username: '2aec254c-8016-480f-a62a-49b1dd9ce532',
password: 'fPJSUToKj7Du'
}
);
// Synthesize speech and then pipe the results to a file
textToSpeech
.synthesize({
text: contents,
voice: "en-US_AllisonVoice", // Optional voice
accept: 'audio/wav' // default is audio/ogg; codec=opus
})
.pipe(fs.createWriteStream('output.wav'));
// Retrieve details of all available voices
textToSpeech.voices({}, function(err, res) {
if (err) {
return console.log(err);
}
console.log(JSON.stringify(res, null, 2));
});
// Retrieve details of a specific voice
textToSpeech.voice(
{
voice: 'en-GB_KateVoice'
},
function(err, res) {
if (err) {
return console.log(err);
}
console.log(JSON.stringify(res, null, 2));
}
);
// Pronunciation details for a word
textToSpeech.pronunciation(
{
text: 'iPhone',
format: 'spr', // 'ipa' (default) is only for english voices
voice: 'de-DE_DieterVoice' // optional, defaults to en-US_MichaelVoice
},
function(err, res) {
if (err) {
return console.log(err);
}
console.log(JSON.stringify(res, null, 2));
}
);