0

I got this from the API which is audio if I try it in postman.

enter image description here

the problem is I don't know how to retrieve it and put it in audio in html. I try to put the php://temp in src in audio html but it not work. because I used guzzle I try to use $response->getBody()->getContents() and I think it's the same as file_get_contents() in php but it shows nothing when I print it. please help in postman it can work but I don't know how to get it.

Qube
  • 543
  • 3
  • 9
  • 23
  • Try `(string)$resp->getBody();` - if it's empty, it's empty. I haven't done much work with audio though – zanderwar Jun 16 '21 at 03:07
  • yes I already try it it's not empty but it string so I don't know how to make it to the audio html or play the audio – Qube Jun 16 '21 at 03:10
  • You could potentially stream it from the src configured in ` – zanderwar Jun 16 '21 at 03:39
  • didn't you just ask a similar question – bhucho Jun 16 '21 at 08:15
  • sorry I ask in different way that may be someone understand but I just got the answer in my old question – Qube Jun 16 '21 at 12:11

1 Answers1

0

well in the lastest guzzlehttp document.you should iterate the body like this

$body = $response->getBody();
while (!$body->eof()) {
    echo $body->read(1024);
}

or better way save stream response to file

$body = $response->getBody();
file_put_contents('/webroot/file.mp3',$body);

then set html src

<audio src="file.mp3"></audio>
nay
  • 1,725
  • 1
  • 11
  • 11
  • I try the while but it echo nothing and I also try with file_put_contents and when I var_dump it it says int(23596). is there something wrong? – Qube Jun 16 '21 at 04:23
  • dose the file contain something? – nay Jun 16 '21 at 06:19