Build an Alexa or Siri Equivalent Bot in Python Using OpenAI in minutes!
- Andrew Hershy
- Oct 14, 2022
- 3 min read
A step-by-step guide to building an AI assistant

Table of Contents
Introduction
Introduction
It’s not as difficult as you think to build an AI program that listens to speech and answers questions. We can make the magic happen in an afternoon by leveraging a few python packages and APIs.
Here are some back-and-forth questions and answers between me and the bot:
Me: What is the population of Brazil?
Bot: The population of Brazil is estimated to be over 209 million people
Me: What does ice cream taste like?
Bot: Most ice cream tastes sweet and creamy
Me: How do I use chopsticks?
Bot: To use chopsticks, you must hold one in each hand. Place the chopstick in your dominant hand between your thumb and index finger, and hold it in place with your middle finger. Place the chopstick in your non-dominant hand between your thumb and index finger, and hold it in place with your ring finger and pinky finger. To pick up food, use the chopstick in your dominant hand to hold the food in place, and then use the chopstick
Granted, these aren’t the most enlightening answers. And that chopstick one at the end is a bit strange, lol. However, the fact that this application can interpret speech and answer questions, no matter how seemingly limited, is amazing in my opinion. And unlike the mainstream AI assistance bots, we can see what’s under the hood here and play around with it.
What This Program Does
Run the file via the command prompt when the user is ready to ask a question
Pyaudio enables the computer mic to pick up speech data
JSON data is sent to AssemblyAI API to be converted to text. Text data is then sent back
Text data is sent to OpenAI API to be channeled into the text-davinci-002 engine for processing
The answer to the question is retrieved and shown on the console below your question
APIs and High-Level Design
This tutorial utilizes two core APIs:
AssemblyAI to transcribe the audio into text.
OpenAI to interpret the question and return an answer. It has also come to my attention that you can leverage OpenAI’s Whisper API to perform the transcription function as well.
Design (high level)
This project is broken up into two files: main and openai_helper.
The ‘main’ script is used for the voice-to-text API connection. It involves setting up a WebSockets server, filling in all the parameters required for pyaudio, and creating asynchronous functions required for sending and receiving the speech data concurrently between our application and AssemblyAi’s server.
The `openai_helper` file is short and is used solely to connect to the open ai “text-davinci-002” engine. This connection is used to receive answers to our questions.
Code Breakdown
main.py
First, we import all the libraries our application will use. Pip installation may be required for some of these, depending on whether you’ve used them. See the comments for context below
Then we set up our pyaudio parameters. These inputs are default settings found in various places on the web. Feel free to experiment as needed, but the defaults worked fine for me. We set the stream variable as our initial container for the audio data, and then we print the default input device parameters as a dictionary. The keys of the dictionary mirror the data fields of PortAudio’s structure. Here’s the code:
Next, we are creating multiple asynchronous functions for the sending and receiving required to transform our verbal questions into text. These functions are running concurrently, which enables the speech data to be converted into base64 format, converted into JSON, sent to the server via API, and then received back in a readable format. The WebSockets server is also a vital piece of the script below, as that’s what makes the direct stream as seamless as it is.
Lastly, we have our simple API connection to openai. If you look at line 44 of the gist above (main3.py), you can see we are pulling the function ask_computer from this other file and using the output as the answers to our questions.
Conclusion
This was a neat project for anyone interested in playing around with the same technology that makes Siri or Alexa function. Not much coding experience is required because we leverage APIs to do our processing. I would highly recommend forking the repo of this project and playing around first-hand if any reader wants to learn more about these technologies. Cheers!
Update: Please check out another project similar to this if you found this one interesting. It’s related to using speech-to-text transcription to create dalle-mini images
This article was originally published here.
Bangalore, known as the Silicon Valley of India, is a city that blends technology, culture, and luxury living. With a growing population of professionals, expats, and travelers, the demand for elite companionship services in Bangalore has increased significantly. Call girls Bangalore offer not only physical intimacy but also emotional comfort, companionship, and a luxurious lifestyle experience for those seeking more than just a casual encounter.
The world of call girls in Bangalore is about luxury, companionship, and discretion. Whether you are a business traveler, an expat, or a local seeking connection, Bangalore escorts offer experiences tailored to your needs. From independent companions to elite models, the choices are vast and diverse, ensuring everyone finds the right match.
Read More :- Bangalore call girls .
https://mounityagi946.hashnode.dev/call-girls-in-bangalore-a-complete-guide-to-premium-companionship-services
https://www.swordcrowncaravans.com/index.php?journal_blog_post_id=7&route=journal3%2Fblog%2Fpost
https://www.theallianceokc.org/single-post/holiday-festivities-highly-anticipated-in-okc?commentId=77618843-1cfa-4f2a-8a78-77aa83da70c2
https://www.theangelofbow.co.uk/forum/main/comment/3f686f58-73f6-4ba4-ad51-53997cc940c2?postId=64b81c09dfc5690010eae6c6
https://www.theboredapegazette.com/post/last-plunge-bayc-s-dookey-dash-unclogged-esports-tournament-ends-tomorrow-with-1-million-in-prize?commentId=b5826677-07cb-4a93-93d1-a3e039d1d4f7
Radhika is an independent Jaipur call girls Service who carries herself with ambition and pride. She is hardworking, goal-driven, and knows how to balance her personal and professional life. Her confidence and determination reflect in the way she interacts, leaving a lasting impression on everyone she meets.
https://menkamahajan.com/jaipur-call-girls/
https://radhikamehta9543.hashnode.dev/delhi-call-girls-ultimate-guide-to-premium-escort-services-in-the-capital
https://www.theallianceokc.org/single-post/holiday-festivities-highly-anticipated-in-okc?commentId=8e8bfab2-eadd-49b3-a59c-9f5b65b86ec2
https://www.theangelofbow.co.uk/forum/main/comment/cb75ec7c-a76d-4bd8-9064-17d5039de1a1?postId=64b81c09dfc5690010eae6c6
https://www.theboredapegazette.com/post/last-plunge-bayc-s-dookey-dash-unclogged-esports-tournament-ends-tomorrow-with-1-million-in-prize?commentId=16238582-2b3f-4840-9dff-9489c8abde83
Meet Rishika, a lively and adventurous Ahmadabad call girls who loves bringing happiness into people’s lives. She is full of energy, playful by nature, and always ready to make every moment exciting. Whether it’s a casual outing or a private evening, Rishika knows how to keep the spark alive.
https://kritikarai.in/ahmedabad-call-girls/
https://www.swordcrowncaravans.com/index.php?journal_blog_post_id=7&route=journal3%2Fblog%2Fpost
https://www.theallianceokc.org/single-post/holiday-festivities-highly-anticipated-in-okc?commentId=51727610-c7cb-425e-9079-ad74411d5066
https://www.theangelofbow.co.uk/forum/main/comment/465fbfba-e8a8-47f6-ad69-c5c92985bf25?postId=64b81c09dfc5690010eae6c6
https://www.theboredapegazette.com/post/last-plunge-bayc-s-dookey-dash-unclogged-esports-tournament-ends-tomorrow-with-1-million-in-prize?commentId=61f59192-7aa6-4913-9588-e87afa611aa0
Vanshika is a stylish personality from Indore escort, known for her sophistication and graceful presence. She has a modern outlook while staying deeply connected to her roots. With her sharp sense of style and vibrant character, she easily stands out wherever she goes.
https://vanshikaa.in/call-girls-indore/
https://www.swordcrowncaravans.com/index.php?journal_blog_post_id=7&route=journal3%2Fblog%2Fpost
https://www.theallianceokc.org/single-post/holiday-festivities-highly-anticipated-in-okc?commentId=70e861df-3677-4958-844e-74d0f9ed3569
https://www.theangelofbow.co.uk/forum/main/comment/d8e64788-b3ec-4ae6-a346-cd37e200b1dc?postId=64b81c09dfc5690010eae6c6
https://www.theboredapegazette.com/post/last-plunge-bayc-s-dookey-dash-unclogged-esports-tournament-ends-tomorrow-with-1-million-in-prize?commentId=e6c47cef-8275-4358-a1bd-699ff2ce8802
Lucknow, the City of Nawabs, is not only famous for its royal heritage, cultural charm, and architectural beauty, but also for its discreet and luxurious escort and call girl services. In today’s world, companionship goes beyond just spending time; it’s about creating memorable experiences, comfort, and understanding. Our detailed guide explores the world of Lucknow call girls, their services, and how they are redefining companionship for individuals seeking intimacy, relaxation, and exclusive moments.
Lucknow’s call girls are redefining the concept of companionship by offering privacy, sophistication, and unforgettable experiences. Whether you are a traveler, a professional, or someone seeking intimacy, these services provide exactly what you desire—discretion, trust, and satisfaction.
Read More :- Lucknow call girls | Bangalore call girls | Hyderabad call girls | Jaipur call girls |…