<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ariyan Ashfaque Mostafa</title>
    <description>The latest articles on DEV Community by Ariyan Ashfaque Mostafa (@ariyan0047).</description>
    <link>https://dev.to/ariyan0047</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F825390%2Ffe9e2e83-a8ec-4331-8d73-7152f9d917ba.jpeg</url>
      <title>DEV Community: Ariyan Ashfaque Mostafa</title>
      <link>https://dev.to/ariyan0047</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ariyan0047"/>
    <language>en</language>
    <item>
      <title>How to convert audio.mp3 to audio.flac?</title>
      <dc:creator>Ariyan Ashfaque Mostafa</dc:creator>
      <pubDate>Fri, 04 Mar 2022 13:21:17 +0000</pubDate>
      <link>https://dev.to/ariyan0047/how-to-convert-audiomp3-to-audioflac-4gca</link>
      <guid>https://dev.to/ariyan0047/how-to-convert-audiomp3-to-audioflac-4gca</guid>
      <description>&lt;p&gt;Google cloud speech to text only accepts flac or raw formatted audio files. I want to convert an audio.mp3/wav file to audio.flac but the converter functions I am using is not working properly. Can anyone suggest me a better way to convert audio.mp3/wav file to audio.flac.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const SpeechToText = function (audioFileData, contentType) {
  try {
    let reader = new FileReader();
    contentType = contentType.toLowerCase();
    return new Promise((resolve) =&amp;gt; {
      reader.onload = function (event: any) {
        let data = event.target.result.split(",");
        let b64Data = data[1];
        let blob = getBlobFromBase64Data(b64Data, contentType);
        let blobUrl = URL.createObjectURL(blob);
        let fileName = audioFileData.name.substring(
          0,
          audioFileData.name.lastIndexOf(".")
        );

        let convertedAudio = {
          path: blobUrl,
          type: contentType,
          name: `${fileName}.flac`,
        };

        resolve(convertedAudio);
      };
      reader.readAsDataURL(audioFileData);
    });
  } catch (e) {
    console.log("Error occurred while converting : ", e);
  }
};

function getBlobFromBase64Data(b64Data, contentType, sliceSize = 512) {
  const byteCharacters = atob(b64Data);
  const byteArrays = [];

  for (let offset = 0; offset &amp;lt; byteCharacters.length; offset += sliceSize) {
    const slice = byteCharacters.slice(offset, offset + sliceSize);

    const byteNumbers = new Array(slice.length);
    for (let i = 0; i &amp;lt; slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i);
    }

    const byteArray = new Uint8Array(byteNumbers);
    byteArrays.push(byteArray);
  }

  const blob = new Blob(byteArrays, { type: contentType });
  return blob;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>angular</category>
      <category>cloudapi</category>
    </item>
  </channel>
</rss>
