Last active
April 20, 2016 14:34
-
-
Save trahloff/c02a36a244d2b5ed406aa3fb5e51596e to your computer and use it in GitHub Desktop.
temp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// client | |
function tts(text) { | |
var url = 'http://localhost:8080/nlc/synthesize'; | |
var req = { | |
method: 'POST', | |
url: url, | |
responseType: 'blob', | |
data: { | |
"text": text | |
}, | |
headers: { | |
'Content-Type': 'application/json', | |
} | |
} | |
$http(req).then(function(response) { | |
console.log(response); | |
audio.pause(); | |
audio.src = URL.createObjectURL(response.data); | |
audio.play(); | |
}) | |
}; | |
//server: | |
app.post('/nlc/synthesize', function(req, res, next) { | |
if (req.body.text == "When shall we meet again?") { | |
var transcript = textToSpeech.synthesize({ | |
voice: 'en-US_AllisonVoice', | |
text: "In thunder, darkness or in rain. When the hurlyburly's done, when the batlle's lost, and won." | |
}); | |
transcript.pipe(res); | |
} else { | |
var text = req.body.text; | |
var deviceId = "node-red"; | |
dlg.classify(deviceId, text, function(err, result) { | |
console.log(result); | |
var transcript = textToSpeech.synthesize({ | |
voice: 'en-US_AllisonVoice', | |
text: result | |
}); | |
transcript.pipe(res); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment