UNPKG

computes-dictation

Version:
47 lines (37 loc) 1.29 kB
"use strict"; var request = require("request"); // var https = require("https"); // var url = require("url"); // var constants = require('constants'); var SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1'); var through2 = require("through2"); function startDictation(options, callback) { var speech_to_text = new SpeechToTextV1({ username: options.username, password: options.password }); // var urlParams = url.parse(options.audioUrl); // var httpOptions = { // hostname: urlParams.host, // port: 443, // path: urlParams.pathname, // method: 'GET', // }; // var req = https.get(httpOptions, function(res) { // res.pipe(speech_to_text.createRecognizeStream({ content_type: options.contentType, continuous: true })) // .pipe(through2(function(value){ // // console.log(value); // callback(value.toString('utf8')); // })); // }); // req.on('error', function(){ // console.log("============"); // console.dir(arguments); // }); request(options.audioUrl) .pipe(speech_to_text.createRecognizeStream({ content_type: options.contentType, continuous: true })) .pipe(through2(function(value){ callback(value.toString('utf8')); })); } module.exports = startDictation;