title: m4a/mp3 files to wav for Bing Speech API
body: <p>Bing Speech API only accepts wav files so I have been trying to convert m4a (Skype) and mp3 (Facebook) audio files I am getting in my chatbot to wav format. I am using fluent-ffmpeg in node.js.</p>
  
  <p>For now, I am downloading the audio file, converting it to wav and returning the piped output for use ahead.</p>
  
  <pre><code>if (attachment.contentType === 'audio/x-m4a') {
    request.get(attachment.contentUrl).pipe(fs.createWriteStream('file.m4a'));
    var command = ffmpeg('file.m4a')
          .toFormat('wav')
          .on('error', function (err) {
              console.log('An error occurred: ' + err.message);
          })
          .on('progress', function (progress) {
              // console.log(JSON.stringify(progress));
              console.log('Processing: ' + progress.targetSize + ' KB converted');
          })
          .on('end', function () {
              console.log('Processing finished !');
          });
  
    return command.pipe();
  }
  </code></pre>
  
  <p>Right now, the conversion works when I send the m4a file through the botframework-emulator on my pc. But when I specify my pc as the endpoint (through ngrok) and try to send the m4a file from the chat test at the bot framework <a href="https://dev.botframework.com/" rel="nofollow noreferrer">developer end</a>, ffmpeg returns an error:</p>
  
  <pre><code>An error occurred: ffmpeg exited with code 1: file.m4a: Invalid data found when processing input
  </code></pre>
  
  <p>But when I play the downloaded m4a file, it plays alright.</p>
  
  <p>The content URL is https in the second case if that matters.</p>
  
  <p>Kindly help me with two things:</p>
  
  <ol>
  <li>Downloading, Converting and Returning without storing anything on my end</li>
  <li>Downloading/Accessing m4a/mp3 files properly</li>
  </ol>
  
  <p>I am new to streams, pipes and ffmpeg and all the above code is after googling. </p>