forked from chomado/GoogleHomeHack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoiceTextWriter.js
39 lines (35 loc) · 1.11 KB
/
VoiceTextWriter.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
var fs = require('fs');
var VoiceText = require('voicetext');
var OUT_PATH = '/Users/chomado/Workspace/GoogleHomeHack/Data/mp3/temp.mp3'
class VoiceTextWriter{
constructor(voiceKey) {
this.voice = new VoiceText(voiceKey);
}
convertToText(text) {
var self = this;
return new Promise(function(resolve,reject) {
self.voice
.speaker(self.voice.SPEAKER.BEAR)
.emotion(self.voice.EMOTION.HAPPINESS)
.emotion_level(self.voice.EMOTION_LEVEL.HIGH)
.volume(150)
.speak(text, function(e, buf) {
if(e){
console.error(e);
reject(e);
} else {
fs.writeFileSync(OUT_PATH, buf, 'binary');
resolve(OUT_PATH);
}
});
});
}
}
module.exports = VoiceTextWriter;
/*
curl "https://api.voicetext.jp/v1/tts" \
-o "test.mp3" \
-u "(APIキー):" \
-d "text=ちょまどだよー" \
-d "speaker=bear"
*/