Create Your Own Magical Storybook Powered by OpenAI and a Raspberry Pi 4

Simply speak your prompt into this special book and watch as it creates a story in real-time that can be read by the page.

The idea

Stories, whether they are fantasy, fairy tales, based on real events, or one of the other myriad of genres, are how information and entertainment has been passed throughout human society for thousands of years. The modern age, however, has brought new ways of creating and sharing them, and with the release of generative AI tools, the ability for computers to create them from scratch. Adafruit contributor Erin St Blaine (firepixie) has taken this concept and run with it, as her magical storybook project can display entirely new stories to the user with just a simple audio prompt.

Getting the components

The core of the book was built around the Raspberry Pi 4 8GB single board computer due to its relatively small size and powerful processing and connectivity options. Users can give their prompts via speech simply by speaking into an attached USB microphone while a NeoPixel LED shows the current status of the device. Finally, the AI model's output is shown on a 7" touchscreen display where the user can interact with the book in a natural fashion.

AI integration

After connecting the microphone and LED, St Blaine's next step was to configure her OpenAI API key and add the openai Python package to her project which would allow her script to send a predefined prompt along with the user's input to ChatGPT and then receive a text response containing a title and the story itself. Because users need to speak and have their audio turned into text for the prompt, another AI-powered speech-to-text (STT) service gathers data from the connected USB microphone and returns the result.

Building and displaying a book

This magical storybook was constructed by first removing nearly all of its pages, as a deep rectangular shape was cut into the middle for housing the Raspberry Pi 4 and screen. After adding the RGB LED and microphone, several decorations were glued to the outside to give it a more mystical feeling. Lastly, a battery pack was added to the Pi before St Blaine loaded the two Python scripts and a ChatGPT prompt template.

Generating a story

Once completed, the magical storybook's users are able to open it up, wait for the LED to turn yellow, and then proceed to describe their ideal adventure before the screen returns with a book. On each page are navigation controls for advancing the pages or for going back to the start to create an entirely new story. Closing the book triggers the magnetic reed switch to place the system into a sleep mode, thus saving power for when it is not being used. St Blaine's extremely thorough and detailed project write-up can be found here on Adafruit's website or on YouTube.

Evan Rust
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles