node-microphone icon indicating copy to clipboard operation
node-microphone copied to clipboard

Windows 10 SoX issue

Open spoggie opened this issue 9 years ago • 10 comments

I am trying to run the node-microphone example on my Windows 10 machine. It is crashing with the following error

SoX is installed and added to the Environment Path

`events.js:160 throw er; // Unhandled 'error' event ^

Error: spawn sox ENOENT at exports._errnoException (util.js:1026:11) at Process.__dirname.ChildProcess._handle.onexit (internal/child_process.js:193:32) at onErrorNT (internal/child_process.js:359:16) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9) at Timeout.Module.runMain as _onTimeout at tryOnTimeout (timers.js:232:11) at Timer.listOnTimeout (timers.js:202:5) Press any key to continue...`

How can I fix this ?

spoggie avatar Sep 06 '16 19:09 spoggie

Hi @spoggie , recently updated the module with an new API. Your error looks like a permission error, try to run it as administrator. Also try to run sox from the command line to prove that it really is accessable on your system. Type into your console and it should give you some binary output: sox -b 16 --endian little -c 1 -r 16000 -e signed-integer -t waveaudio default -p

Flowr-es avatar Sep 10 '16 10:09 Flowr-es

Hi @MexXxo , I am now receiving some output on the console - no admin permission required.

The issue is, if I am importing the output to Audacity it gives me good results when importing as Stereo but in my settings I wanted to use mono. So it seems like sox does not properly record as Mono. When importing as Stereo in Audacity, I am getting a silent and a playback stream that sounds right.

var mic_options ={ 'endian' : 'little', 'bitwidth' : '16', 'encoding' : 'signed-integer', 'rate' : '16000', 'channels' : '1' } var fs = require('fs'); var file = fs.createWriteStream('test.wav', { encoding: 'binary' }); var Mic = require('node-microphone'); var mic = new Mic(mic_options); var micStream = mic.startRecording(); micStream.pipe(file); setTimeout(() => { console.log('stopped recording'); mic.stopRecording(); }, 30000);

PS: I also liked in your prior Implementation the callback with Audio information. It was not a bad idea to separate information from the audio stream.

spoggie avatar Sep 12 '16 07:09 spoggie

Ah okay good to know, this explains also why I needed to add 2 channels as wav header.

For info and error take a look into the latest update :) they are back as events.

Flowr-es avatar Sep 16 '16 18:09 Flowr-es

were you able to fix the channel issue as well ?

spoggie avatar Sep 16 '16 22:09 spoggie

I will take a look into it, but probably this is an sox issue. Than the fix would be here to update the documentation.

Flowr-es avatar Sep 17 '16 11:09 Flowr-es

@spoggie I had the same issue, what fixed it for me was adding the "sox.exe" file to the system environment variable called "path".

sox.exe is located in the folder where you installed sox. For me this was C:\Program Files (x86)\sox-14-4-2

If you look closely at the error it says windows can't find the "sox" command. If you do above fix -->AND RESTART YOUR COMPUTER<-- You will be ok :D

DutchErikNL avatar Oct 23 '16 17:10 DutchErikNL

@MexXxo Hey i'm trying to use your library to fulfull this stackoverflow question: http://stackoverflow.com/questions/38395045/stream-audio-from-pc-to-smartphones

Do you think it's possible?

DutchErikNL avatar Oct 23 '16 17:10 DutchErikNL

Well you get a NodeJs Audio Stream from this module. So yes, looks possible. The only thing, with this module you need sox as an external dependency and it looks like sox on windows will give you a 2 channel even if it is mono audio, soxs adds a second channel.

I haven't tested it on Windows 7, but on Windows 10 it worked.

Flowr-es avatar Oct 29 '16 09:10 Flowr-es

Hi @MexXxo , I use this code

record .start({ sampleRateHertz: sampleRateHertz, threshold: 0, sampleRate : 16000, // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options verbose: false, recordProgram: 'sox', // Try also "arecord" or "sox" silence: '3.0' }) .on('error', console.error) .pipe(recognizeStream);

  • nodejs v4.8.4
  • sox-14-4-2
  • Win 10

on linux i put recordProgram: 'rec' works. on windows recordProgram: 'sox' does not work (it is as if the sound from the microphone did not come). Sox it's installed. If I try to run sox in this way "sox -t waveaudio -d prova.flac" works

Do I have to enter the channel or device? I tried but did not go. Could you suggest me something? Thanks

domorso avatar Oct 02 '17 19:10 domorso

On Windows 10 + Google Speech I encountered the same problem that the file returned by sox is 32-bit, while Google Speech expects 16 bit. I found a solution for this problem here. The following works for me: sox -t waveaudio default -b 16 -c 1 -e signed-integer -r 16000 --endian little -t wav - > voice.wav

bsluis avatar Jan 07 '19 09:01 bsluis