Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
how to send audio stream between child processes in nodejs

How do i properly send stream to a child process. I am trying to stream audio from client to server using this method

I am getting the audio stream from client


const ss = require('socket.io-stream');
const socketIo = require('socket.io');

server = http.createServer(app);
io = socketIo(server);

const child_process = childProcess.fork('./child_process.js');


io.on('connect', (client) => {


    // when the client sends 'stream-transcribe' events
    // when using audio streaming
    ss(client).on('stream-transcribe', function(stream, data) {
     
    var combine_data = {
            "data": data,
            "stream": stream,
            "event":"new_stream"
          }
    
     child_process.send(combine_data)


  }


}
 

this call

     child_process.send(combine_data)

throws the error

node:internal/child_process/serialization:127 const string = JSONStringify(message) + '\n'; ^

TypeError: Converting circular structure to JSON --> starting at object with constructor 'Namespace' | property 'server' -> object with constructor 'Server' | property 'nsps' -> object with constructor 'Object' --- property '/' closes the circle at stringify () at writeChannelMessage (node:internal/child_process/serialization:127:20) at ChildProcess.target._send (node:internal/child_process:837:17) at ChildProcess.target.send (node:internal/child_process:737:19) at Socket. (/Volumes/GoogleDrive/My Drive/app/server.js:236:40) at Socket.onstream (/Volumes/GoogleDrive/My Drive/app/node_modules/socket.io-stream/lib/socket.js:184:14) at Socket.emit (node:events:526:28) at Socket. (/Volumes/GoogleDrive/My Drive/app/node_modules/component-bind/index.js:21:15) at Socket.emit (node:events:526:28) at /Volumes/GoogleDrive/My Drive/app/node_modules/socket.io/lib/socket.js:528:12

Node.js v17.5.0

what is causing the error and how can I send the stream to child_process ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Any data you send using child_process.send() will be converted to a string using JSON.stringify(). The data you try to send is too complex to be converted to a string. In particular, it uses circular references. You can easily verify this using console.log() or a debugger.

You can try to send only data that can be converted to a string. You probably should not try to send stream at all and only send the relevant fields of data.

Otherwise, you can probably pipe() the stream to stdin of the child process.

Based on the documentation:

ss(client).on('stream-transcribe', function(stream, data) {
  stream.pipe(child_process.stdin);
});

In the child process you can read the data from stdout, which is a readable stream.

child_process.stdout.on('data', (chunk) => {
  // do something with `chunk`
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda