node.js - Playing audio with python script from a NodeJS server -


i trying play audio file using python. while need reproduce audio file, i'll use gpio @ raspberry.

when receive http related link, it's supposed execute python script , reproduce audio. but, api reproduces short sound. file have 10 sec noise plays less 1 sec.

here controller

// controller  /* importar o módulo child_process */ var cp = require('child_process');  /* importar o módulo node-omxplayer */ var omx = require('node-omxplayer');  /* importar o módulo python-shell */ var ps = require('python-shell');  // caminhos para os scripts pythons var options = {     scriptpath: '/home/pi/documents/apirest/api/files/' };  /* o módulo node-omxplayer usar o child_process para execução da query de reprodução omxplayer */  module.exports.parar = function(application, req, res) {     res.send('comando de parada video foi executado');      cp.exec('killall omxplayer.bin', function(err, stdout, stderr){         if(err)         {             return;         }     }); }   module.exports.repr = function(application, req, res) {     var query = req.query.video;      if(query == '1')     {         res.send('script de reprodução video 1 sendo executado.');         vd1 = omx('/home/pi/downloads/video1.mp4', 'hdmi');     }     else if(query == '2')     {         res.send('script de reprodução video 2 sendo executado.');         vd2 = omx('/home/pi/downloads/video2.mp4', 'hdmi');     } }  module.exports.trovao = function(application, req, res) {     var out = '';      ps.run('trovao.py', options, function (err) {         if (err)         {              out = err;             throw err;         }         else         {             out = 'ok';         }          console.log('finished');             res.send("status: " + out);     }); } 

i tried use child_process execute script, have same result. small noise. when execute script directly, python trovao.py works!!

here python script:

import pygame.mixer pygame.mixer import sound time import sleep  pygame.mixer.init()  try:      thunder = pygame.mixer.sound("thunder3.wav")     print ("arquivo carregado!") except pygame.error:     print ("nao foi possivel carregar o arquivo!")  #executa o som somente uma vez aux = thunder.play() while aux.get_busy():     continue     #pygame.time.delay(100) #sleep(2) #thunder.stop() print("reproduzido"); 

in fact, need play audio file , sync gpio interaction. what doing wrong?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -