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

198
Visualizações
How to play audio from an API response?

I'm not able to play audio from the below response. How can I convert that below response and play it.

getAudio = async () => {
try {
const url = `example`;

const r = await fetch(url).then(r => r.text());
const len = r.length;

let audioURL = "";

if (len > 200) {
  const buf = new ArrayBuffer(len);
  const view = new Uint8Array(buf);

  for (let i = 0; i < len; i++) view[i] = r.charCodeAt(i) & 0xff;

  const blob = new Blob([view], { type: "audio/wav" });

  audioURL = window.URL.createObjectURL(blob);
} else toast("No audio found!", { type: "error" });

this.setState({ audioURL });
} catch (e) {
console.log(e);
}
};

Response is

enter image description here

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

0

I would try to use Axios instead of Fetch, Its more useful in my opinion, Other than that, try setting up an error boundary around the definition of blob, I truly believes the problem lays there.

Good luck!

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