How do you encode mp3 text content to mp3 clip file?

I want a method to convert mp3 string content like this :arrow_down:

audio1.txt (4.0 KB)

or

this :
audio.txt (94.6 KB)

how to convert a .txt file mp3 content to an mp3 clip file ,when I drag mp3 file to notepad I get content like encoded string but when I rename the file from .txt to .mp3 it doesn't work as an mp3 file to play it
to mp3 file clip that can I play
thanks

You can see binary data represented in text format.

What you want to do will not work.

Convert mp3 to base64 if you want it as a string....

You can then make a datauri which should playback in a webview:

data:audio/mp3;base64, base64 string

thanks, @TIMAI2 ,I want to use the method to convert the response of TTS API of OpenAI TO mp3 file so I can deal with it as an mp3 clip .

please check the API to understand what I mean
and if you show me with blocks or extension how to do this I would be thankful

Looks like you might need something like this:

Api returns mp3 file's content (bytes) itself. Just write bytes to a file.

I have already tried this I saved the content to the file named for example name.mp3
but when I tried to play I got an error saying "unsupported audio file"

could you show a blocks example for how to do this

Do I need to add a card to enable api key?
I am getting below message:

You exceeded your current quota, please check your plan and billing details.

I think this should be sufficient for you.

        URL url = new URL("https://api.openai.com/v1/audio/speech");
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setRequestMethod("POST");

        httpConn.setRequestProperty("Authorization", "Bearer " + TOKEN);
        httpConn.setRequestProperty("Content-Type", "application/json");

        httpConn.setDoOutput(true);
        OutputStreamWriter writer = new OutputStreamWriter(httpConn.getOutputStream());
        writer.write("{\n    \"model\": \"tts-1\",\n    \"input\": \"The quick brown fox jumped over the lazy dog.\",\n    \"voice\": \"alloy\"\n  }");
        writer.flush();
        writer.close();
        httpConn.getOutputStream().close();
        InputStream responseStream = httpConn.getInputStream();
        OutputStream outputStream = new FileOutputStream("D:\\tts.mp3");
        byte[] b = new byte[4096];
        int c;
        while ((c = responseStream.read(b)) != -1) {
            outputStream.write(b, 0, c);
        }
        responseStream.close();
        outputStream.flush();
        outputStream.close();

No, but if your free trial expired your should add more balance by card ,

thanks, @vknow360 I will try it

I created api key, opened IDEA and clicked run.
That's how my free trial expired.

you can check your balance first

thanks @vknow360 it works fine with me