node.script Error in Speech-to-Text-Application

    Javascript

    Christopher's icon
    Christopher's icon
    Christopher
    Mar 01 2023 | 8:07 pm
    Hi guys n gals,
    DeepGramSTT.maxpat
    maxpat 6.16 KB
    I have pasted together, with all my love, this .js-file to run in node.script. (absolute Javascript rookie). Via node-record-lpcm16 it accesses the microphone and streams the audio to the Deepgram API. The latter transcribes it and it shall be output as text through node.script’s outlet to MAX. Deepgram takes care of all the parsing and endpoints of speech, good quality stuff!
    Running the .js through node in terminal works (therein not running the maxApi-part, of course), but when running in node.script it crashes with the debugger saying:
    Error: spawn sox ENOENT at Process.ChildProcess.handle.onexit (node.internal/child_process:282:19) at onErrorNT (node:internal/chil_process:480:16) at processTicksAndRejections (node:internal/process/task_queues:83:21)
    I’d be so happy if anyone had any ideas… Or alternatives how to access a microphone for the Deepgram API.
    (Of course I have an API key, runninng LTS of node, all the packages are installed – maybe it is some file localization trouble?)
    Thanks, Chris

    • mattyo's icon
      mattyo's icon
      mattyo
      Mar 02 2023 | 4:03 pm
      I don't know if this is helpful, but I might as well put it out here: I've been working on a similar project in node.js using Vosk, and I'm having a similar experience -- it runs fine in the Terminal, but in Max I'm getting a spawn error for 'rec', which is also part of the SoX package.
      I was guessing that it might have been a $PATH issue with SoX, but that looks good on my end, so it might be some other kind of Max/SoX crankiness.
      You might want to check your $PATH situation with SoX -- a possible longshot, but worth checking, I guess. Have a look at this thread:
      https://cycling74.com/forums/sox-in-node-js
      hth,
      \M
      Share
    • Christopher's icon
      Christopher's icon
      Christopher
      Mar 02 2023 | 9:52 pm
      Hi MATTYO,
      thank you for all the hints, gotta be some Max/SoX crankiness.... And thanks for pointing me to https://cycling74.com/forums/sox-in-node-js. Pulling SoX into the PATH variable at runtime, as pointed out by Florian Demmer, worked perfectly for me – you're a life saver! Also, I might check out Vosk – my free DeepGram credit is deplenishing rapidly... I'm leaving the fixed patch here if anyone cares, it's working Speech-to-Text, not fine tuned however... Chris
    • mattyo's icon
      mattyo's icon
      mattyo
      Mar 07 2023 | 12:22 am
      Glad to be of help -- unfortunately, still isn't working for me -- I'll have a look at your code though, & see if that helps! I was looking at Vosk because the dictionary resides on your machine, so no lookup delay....
      Onward through the fog!
      \M
    • mattyo's icon
      mattyo's icon
      mattyo
      Mar 07 2023 | 1:27 am
      Hey Christopher, Being a lazy-ass, I assumed that since $PATH was returning /usr/local/bin (where my copy of sox lives), my script would find it, but forcing it with the split did it! Thanks for inspiring me to get off my ass!
      \M
    • Christopher's icon
      Christopher's icon
      Christopher
      Mar 13 2023 | 1:31 pm
      That's so nice! Look at us, we did it ;)
    • mattyo's icon
      mattyo's icon
      mattyo
      Mar 13 2023 | 3:08 pm
      Just FYI, I'm having pretty good results with Vosk, especially the larger models. They're a tad slower than the smaller ones, but definitely more accurate... have you checked it out?