Close

Getting Keyed

A project log for Positivity Pusher | infinite affirmation generator

Hear a new encouraging phrase with every push

stephSteph 07/04/2023 at 04:570 Comments

Positivity Pusher needs two API keys to function. 

Here's how to get them.

After each button press, Positivity Pusher connects to OpenAI to generate new text, and Microsoft's Azure cloud services to generate the speech. The keys are basically how Positivity Pusher signs in to those services. Once you have them, you'll put them in the settings.toml file on your CIRCUITPY drive using any text editor. To start, the file should look like this:

OpenAI:

This one is easy. Just go to openai.com and sign up for an account. You'll have to supply a credit card at some point. Next, click on your profile in the upper right corner of the page and select "View API keys"

Next, click the button to generate a new key:

That's it! You can now copy the API key and paste it into the settings.toml file. Note that this key begins with "Bearer", leave that in place and replace only the x-es. You can only view this key once, so be sure to copy it to somewhere safe. If you lose it, you'll need to generate a new one. 

Microsoft/Azure TTS:

This process is a lot harder because it's Microsoft so of course it is. The good news is that it's free. 

First, you'll need an account. We'll end up selecting a free tier later, but you will still have to provide a credit card in order to get set up. I know it sounds sketchy, but I've done it myself and it's true. The free tier really is free. 

Once you have your account and are logged in, you'll add a Speech Service to your account. 

You'll need to choose a name for your resource group and instance. Pick anything, this won't matter much. Also choose the region closest to you.

Next, choose the free pricing tier, then click the create button. 

From the Speech Service page, click on the name of your instance:

Now, click to manage keys:

Finally, you'll be able to copy your key from this page.

Now that you have both keys, your settings.toml file should look like this:

API Costs

Neural Speech Synthesis:

Microsoft allows a generous 500,000 characters per month on the free tier. By my estimation, that's enough to narrate all of The Hobbit, every month. In my extensive testing of Positivity Pusher, i've never hit the cap, even when pushing the button hundreds of times per day. If you somehow need more affirmations than that, the paid rate is $16 for 1M characters.

AI Text Generation:

Positivity Pusher uses the "3.5-turbo" model from OpenAI, which currently (as of July 2023) has a price of $0.0015 / 1K of input tokens and $0.002 / 1K of output tokens. Of course, those numbers alone don't tell us much. OpenAI says:

Multiple models, each with different capabilities and price points. Prices are per 1,000 tokens. You can think of tokens as pieces of words, where 1,000 tokens is about 750 words. This paragraph is 35 tokens.

"Input tokens" refers to the tokens that get sent to OpenAI in the form of the prompt, where "output tokens" are the generated response. 

Positivity Pusher uses about 700-900 input tokens per press, and the response is capped at 100 tokens, usually coming in between 50 and 90 tokens in length. 

With these numbers, we can calculate that each press of the button costs around $0.0014. At that price, two presses per day x 365 days = $1.00

Discussions