コード例 #1
0
function onVoiceMessage(msg){
  var chatId = msg.chat.id;
  bot.getFileLink(msg.voice.file_id).then(function(link){
  	//setup new recognizer stream
  	var recognizeStream = speech_to_text.createRecognizeStream(params);
	  recognizeStream.setEncoding('utf8');
  	recognizeStream.on('results', function(data){
  		if(data && data.results && data.results.length>0 && data.results[0].alternatives && data.results[0].alternatives.length>0){
  			var result = data.results[0].alternatives[0].transcript;
  			console.log("result: ", result);
  			//send speech recognizer result back to chat
  			bot.sendMessage(chatId, result, {
  				disable_notification: true,
  				reply_to_message_id: msg.message_id
  			}).then(function () {
  			    // reply sent!
  			});
  		}

  	});
  	['data', 'error', 'connection-close'].forEach(function(eventName){
  	    recognizeStream.on(eventName, console.log.bind(console, eventName + ' event: '));
  	});
  	//pipe voice message to recognizer -> send to watson
    requests(link).pipe(recognizeStream);
  });
}
コード例 #2
0
ファイル: messenger.js プロジェクト: Glavin001/bot-server
 function getFileLink(resp) {
   return this.bot.getFileLink(resp.file_id)
 }