Socket
Socket
Sign inDemoInstall

node-wit

Package Overview
Dependencies
73
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.2.0 to 6.2.1

lib/lib/config.js

8

lib/interactive.js

@@ -36,2 +36,9 @@ /**

wit.on('partialTranscription', text => {
console.log(text + '...');
});
wit.on('fullTranscription', text => {
console.log(text + ' (final)');
});
rl.on('line', line => {

@@ -76,2 +83,3 @@ line = line.trim();

microphone.start();
console.log('🎤 Listening...');

@@ -78,0 +86,0 @@ return;

58

lib/wit.js

@@ -10,8 +10,10 @@ /**

const fetch = require('isomorphic-fetch');
const Url = require('url');
const EventEmitter = require('events');
const HttpsProxyAgent = require('https-proxy-agent');
const {Readable} = require('stream');
const Url = require('url');
class Wit {
class Wit extends EventEmitter {
constructor(opts) {
super();
this.config = Object.freeze(validate(opts));

@@ -80,5 +82,6 @@ }

return fetch(fullURL, {
const req = fetch(fullURL, {
body,
method,
proxy,
headers: {

@@ -89,11 +92,38 @@ ...headers,

},
})
});
const _partialResponses = req
.then(
response =>
new Promise((resolve, reject) => {
logger.debug('status', response.status);
const bodyStream = response.body;
bodyStream.on('readable', () => {
let chunk;
let contents = '';
while (null !== (chunk = bodyStream.read())) {
contents += chunk.toString();
}
for (const {error, intents, text} of splitHttpChunks(
contents,
).map(x => JSON.parse(x))) {
if (!(error || intents)) {
logger.debug('[speech] partialTranscription:', text);
this.emit('partialTranscription', text);
} else if (text) {
logger.debug('[speech] fullTranscription:', text);
this.emit('fullTranscription', text);
}
}
});
}),
)
.catch(e => logger.error('[speech] could not parse partial response', e));
return req
.then(response => Promise.all([response.text(), response.status]))
.then(([contents, status]) => {
const chunks = contents
.split('\r\n')
.map(x => x.trim())
.filter(x => x.length > 0);
return [JSON.parse(chunks[chunks.length - 1]), status];
})
.then(([contents, status]) => [
JSON.parse(splitHttpChunks(contents).pop()),
status,
])
.catch(e => e)

@@ -153,2 +183,8 @@ .then(makeWitResponseHandler(logger, 'speech'));

const splitHttpChunks = response =>
response
.split('\r\n')
.map(x => x.trim())
.filter(x => x.length > 0);
const validate = opts => {

@@ -155,0 +191,0 @@ if (!opts.accessToken) {

2

package.json
{
"name": "node-wit",
"version": "6.2.0",
"version": "6.2.1",
"description": "Wit.ai Node.js SDK",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc