4

I have a Meteor call which takes the text as parameter and returns the .wav data of that particular text. Now I need to convert that into .mp3 and play that audio in my Meteor app. How can I do this?

Meteor.call("watsonaudio",wusername,wpassword,text, function(error, results) {
        console.log("Insideeeeee");
        if(results){
            console.log("resultsss",results.content);
            var audio = new Audio(results.content);
             //audio.src = results.content;
            audio.play();
            console.log("audio played");
        }

    });

In the above code, results.content has .wav data something like (RIFF����WAVEfmt ....). Now how can I make it play?

ralphearle
  • 1,696
  • 13
  • 18
user7350714
  • 365
  • 1
  • 6
  • 20

1 Answers1

0

If you are simply trying to play the 'wav' audio, then you can just use the HTMLAudioElement interface (which is what it appears that you are currently doing) or howler.js. However, certain Internet Explorer versions are unable to play a 'wav' file so you will want to convert to some other format first.

Since you specifically mentioned that you want to convert to 'mp3', then perhaps you have already encountered IE's 'wav' limitations. Take a look at these examples that detail a couple of different approaches.

  1. Using Recordmp3JS
  2. Using RecorderJS and libmp3lame.js

Also, its important to note that none of these solutions are directly related to Meteor because the problem you are trying to solve is actually not related to Meteor in any way. Keep that in mind in your quest for a solution so that you dont unnecessary constrain yourself while searching.

Lastly, I would highly recommend that you consider performing the 'wav' to 'mp3' conversion on the server since you are going there anyway to get the sound data. It would not make sense to transfer uncompressed 'wav' data to the client when you could be sending compressed 'mp3' data instead.

Community
  • 1
  • 1
jordanwillis
  • 10,449
  • 1
  • 37
  • 42
  • ok @jordan .Thanks finally someone responded.On your suggestion Im trying to make the audio get downloaded from my node js app itself as a response for that rest call..I could succeed only partially.The audio is getting saved in my project folder but Iam unable to download it..Can you help here – user7350714 Mar 12 '17 at 17:11
  • Are you trying to download an audio file or a stream of audio data? – jordanwillis Mar 12 '17 at 18:09
  • audio file.(.mp3)..Currently it is getting saved to my local project folder – user7350714 Mar 12 '17 at 18:20
  • I want to make it downloaded – user7350714 Mar 12 '17 at 18:21
  • reader.on('format', function (format) { console.log(' file read success'); var writer = new wav.FileWriter('output.wav', { channels: 1, sampleRate: 22050, bitDepth: 16 }); reader.pipe(writer); console.log('file write success'); writer.pipe(res); }); tempaudio.pipe(reader); – user7350714 Mar 12 '17 at 18:24
  • the above is how Iam able to save file to my local.But Iam unable to download it – user7350714 Mar 12 '17 at 18:24