Example #1
0
server.on('message', function (message, remote) {  
  // Start of recording
  if(Buffer.from('start').compare(message) === 0) {
    console.log(chalk.yellow('•') +' Now recording...');
    // End of recording
  } else if(Buffer.from('end').compare(message) === 0) {
    console.log(chalk.yellow('•')+' Recording ended, now converting...');
    var buff = Buffer.concat(bufferArray);
    var filename = `recording ${currentTime}.wav`;
    var writer = new wav.FileWriter(`recordings/${filename}`, {
      channels: 1,
      sampleRate: 8000,
      bitDepth: 8
    });
    writer.write(buff);
    writer.end();
    console.log(chalk.green('•') + ' ' + chalk.green(`Recording done!\n`));
    playRecording(filename);
    notifyPartner(remote);  
  } else if(Buffer.from('request-msg').compare(message) === 0) {
    console.log(chalk.green('• Message has been requested!'));
    sendMessage();
  } else {
    try {
      bufferArray.push(message);
    } catch(e) {
      console.log(e);
    }
  }
});
Example #2
0
binaryServer.on('connection', function(client) {
  console.log('new connection');

  var fileWriter = new wav.FileWriter(outFile, {
    channels: 1,
    sampleRate: 48000,
    bitDepth: 16
  });

  client.on('stream', function(stream, meta) {
    console.log('new stream');
    stream.pipe(fileWriter);

    stream.on('end', function() {
      fileWriter.end();
      console.log('wrote to file ' + outFile);
    });
  });
});
Example #3
0
 client.on('stream', function(stream, meta) {
     console.log(COUNT);
       COUNT += 1
       var fileWriter = new wav.FileWriter('demo1.wav', {
         channels: 1,
         sampleRate: 41400,
         bitDepth: 16
       });
       stream.pipe(fileWriter);
       stream.on('end', function() {
         fileWriter.end();
       });
     for(var id in binaryserver.clients){
   if(binaryserver.clients.hasOwnProperty(id)){
     var otherClient = binaryserver.clients[id];
     if(otherClient != client){
       var send = otherClient.createStream(meta);
       stream.pipe(send);
     }
   }
 }
     });
    // environment properties, and then Bluemix's VCAP_SERVICES environment property
    // username: '******',
    // password: '******'
  }
);

const micInstance = mic({
  rate: '48000',
  channels: '1',
  debug: false
});

const micInputStream = micInstance.getAudioStream();

const wavStream = new wav.FileWriter('./audio.wav', {
  sampleRate: 48000,
  channels: 1
});

const recognizeStream = speechToText.createRecognizeStream({ content_type: 'audio/wav' });

micInputStream.pipe(wavStream);

wavStream.pipe(recognizeStream);

recognizeStream.pipe(fs.createWriteStream('./transcription.txt'));

// note:
// If you just kill the process with control-c, the .wav file will have an incorrect header, and any in-flight
// transcription will be lost.
// This allows for a graceful termination of the recording, and the process will automatically exit after everything is
// complete.
Example #5
0
 stream.on('end', function() {
   fileWriter.end();
   console.log('wrote to file ' + outFile);
 });
Example #6
0
 stream.on('end', function() {
   fileWriter.end();
 });