Saving openAI TTS API response with R programming

84 Views Asked by At

HTTR2 does a great job of calling the OpenAI TTS (text to speech) API. However, I am having trouble saving the response from the API in an audio format. Since the API is "new" and Rpackages have not been updated to integrate it, I have to use HTTR2.

I clearly see tons of ways to do it in Python, but what command should I use to save an audio response?

So far I have tried the "av" package. Ultimately, I would like to get something similar to the stream_to_file() function in Python used by others to perform this task.

Thanks

I was thinking the "av" package would let me convert everthing to a mp3 with av_audio_convert(response) and av_audio_convert(response$body). I get an error. Error in path.expand(path) : invalid 'path' argument.

Similarly, I tried pretty much everything with the read functions of the package "av".

The "response" from OpenAI display the following message.

<httr2_response>
POST https://api.openai.com/v1/audio/speech
Status: 200 OK
Content-Type: audio/mpeg
Body: In memory (899520 bytes)
0

There are 0 best solutions below