I wanted a reason to try out some of the OpenAI APIs, so I came up with the idea of generating a short audio recap (could be a daily podcast) of a day’s NBA games.
Example audio output, for the games on November 14, 2023:
Now, the details
This was pretty straightforward to cobble together. Here are the pieces of the code:
First, using the API-NBA on RapidApi, it grabs the box scores for all the games on a given date (1 API call) plus the player stats for each game (1 API call per game). All of this is stored in variables as JSON.
Next, a script for the podcast is generated via the OpenAI text-completion API. Here is the system prompt (which tells the language model how to behave) I used:
You are daily NBA podcaster. Given JSON data for a day of NBA games, write a script for a 5 minute podcast summarizing the most interesting things about the day’s games. Try to be funny and weird. Give the players nicknames sometimes.
(I added the last two sentences after the first run, which was a bit too dry.)
Then, the user prompt (the specific thing the language model is reacting to) just consists of a dump of all the JSON data.
Finally, the script is passed to the OpenAI text-to-speech API, to generate the mp3 file.
More about the results
I about fell out of my chair laughing, the first time I listened to the output. I don’t know why it decided to give the teams (which already have nicknames) additional nicknames, but it’s hilarious (San Antonio “Six Shooters” Spurs). Some other highlights:
Spencer “Did-Win-this” Dinwiddie
Steph “Chef” Curry cooked up a stew with 29 points and seasoned it with 10 assists
In the NBA, the drama’s thicker than a protein shake
Spurs, this isn’t the Alamo, but remember to defend!
Shoot your shot both on and off the court
It still blows my mind what generative AI can do. Spencer “Did-Win-this” Dinwiddie is amazing. I tried using Google to see if anyone else had come up with that nickname, but I couldn’t find anything. If that is the case, that is a truly incredible bit of creativity. I’m definitely going to start using that nickname for him.
The script isn’t perfect, but it is coherent and funny. I’m sure it would be even better if I spent more time tweaking prompts.
Oh no, this costs money
It was my intention, at one point, to set this up to run automatically each day, and maybe I would have a simple website where you could listen to the audio. But, I realized that this would cost money. The API-NBA is free, but the OpenAI APIs are not. Because of the large size of the input (all the JSON data), each run of the text-completion API costs about $1. So… I’m not going to do that (unless someone wants to sponsor it!).
I may run it manually from time to time though, and add the audio files to this post.
Update: more results
November 19, 2023: