otalk / hark

Converts an audio stream to speech events in the browser
571 stars 96 forks source link

recordrtc.js + hark.js = corrupted stream audio records (robotic voice + echo + noise) in safari #41

Closed DevJhns closed 1 year ago

DevJhns commented 5 years ago

Well, using

var options = {};
  var speechEvents = hark(localStream, options);
  speechEvents.on('speaking', function() {
      stream_part();
    });
    speechEvents.on('stopped_speaking', function() {
      stream_recorder.stopRecording(function() {
        io_chunk(stream_recorder.getBlob());
    });
    });
/* */
function stream_part() {
  stream_recorder = new RecordRTC(localStream, { 
      type: 'audio', mimeType: 'audio/wav',
      recorderType: StereoAudioRecorder, numberOfAudioChannels: 1,
      desiredSampRate: 16000
  });
  stream_recorder.startRecording();
  }
  function io_chunk(part) {
    socket.emit('stream', part);
  }

All ok in chrome, but in Safari records corrupts somehow, how to prevent this, any ideas? Thx!

sabrinaheid commented 4 years ago

@DevJhns i had the same problem and i have found a solution. I clone the stream (in your case: localStream and then it works for me: var speechEvents = hark(localStream.clone(), options);

DevJhns commented 4 years ago

@sabrinaheid I found this solution about 1-1.5 months ago, posted it in some issue here already, thx anyway)