I’m very new to OpenAi. I have a paid account, Mac user, VS Code, Python and Github installed on my computer. I can’t for the life of me figure out how to use the feature. I have the secret API key as well. Can anyone help?
There is official documentation here.
If you have already put your API in a secret env file, if you haven’t check out this, you can create a tts.py file and put in this example code:
from pathlib import Path
from openai import OpenAI
client = OpenAI()
speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="This is working!"
)
response.stream_to_file(speech_file_path)
and run it. It will export a .MP3 file that contains the voice selected by the voice variable, saying what you placed as the input. Depending on what you are doing with the TTS model, you may want to use tts-1-hd instead of tts-1. In the documentation that I linked above, you can find information about all of its voices, different supported output formats, etc.
Thank you! I’m more on the design side than the developer side, so it’s all fairly confusing. I tried running the python environment and it wouldn’t. But thanks for that link, it looks like a step by step process. Hopefully it works!
Cool, I personally am more on the backend side and not the frontend UI. Could you provide the error message you receive when you run the script I provided?
I really appreciate your help!
It looks like it ran okay - no problems. But where does it output the .mp3 file and where do you enter the text you want?
You can run:
open .
on a MacOS to open up the file where the .mp3 file is or you can use a file manager and go to the file where it is and see it there.
Change the input variable to instead of This is working whatever you want.
Okay, I know your issue thanks for the screenshots so delete everything above and under the ``` including it. Then rename the file as app.py and send a screenshot of where you are at.
Okay thanks, here it is
Remove the bottom section: [/quote] open . and ‘’’ and then the top should turn grey or yellow.
Okay i did that and then ran it and got this error message
Okay, open up a terminal and copy and paste this command into it:
pip install openai
Then run it again. If you have any issues with it then either running the command above or running the script after you install openai please give me the error message.
It gave me this error once I pasted and hit enter
Thanks, try running
python3 -m pip install openai
Okay, now try running your script.
Try just clicking the run button which looks like a little arrow and see what happens.
It seems you haven’t passed the api key with your request. Have you setup an api key for your project yet? If you haven’t you need to go https://platform.openai.com/api-keys and setup an api key to use with your project/requests.