Add A Voice Chatbot to Your Phone (Telegram)
14:31

Add A Voice Chatbot to Your Phone (Telegram)

The AI Advantage 15.04.2023 31 105 просмотров 1 059 лайков обн. 18.02.2026
Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
Want to add voice output? Check out part 3: https://youtu.be/RopQwkZND8g Try out Hostinger: https://hostinger.com/aiadvantage Use my code at checkout: AIADVANTAGE Today I show you how to build a custom voice-activated chatbot on your phone. Good Tutorial on hosting the script 24/7: https://youtu.be/2TI-tCVhe9k Code: https://github.com/AIAdvantage/chatgpt-telegram-voice-chatbot.git https://drive.google.com/drive/folders/1MI1idmfCBvjujO_IVWIL6GTZUVBYMWt3?usp=sharing Commands: Windows: pip-install-r requirements.txt" MAC: pip3-install-r requirements.txt" 0:00 Step by step 01:29 Simple ChatBot 07:35 Advance Chatbot 09:28 Voice Chatbot #aichatbot #voicechatbot #telegramchatbot My Video Equipment: 📷 Camera: https://amzn.to/3wXedn9 🔍 Lens: https://amzn.to/3wZdIck 🎤 Mic: https://amzn.to/3wXedn9 🔊 Audio Mixer: https://amzn.to/3GmPhdj 💡 Light: https://amzn.to/3GmPhdj Free AI Resources: 🔑 Get My Free ChatGPT Templates: https://myaiadvantage.com/newsletter 🌟 Receive Tailored AI Prompts + Workflows: https://v82nacfupwr.typeform.com/to/cINgYlm0 👑 Explore Curated AI Tool Rankings: https://community.myaiadvantage.com/c/ai-app-ranking/ 🐦 Twitter: https://twitter.com/TheAIAdvantage 📸 Instagram: https://www.instagram.com/ai.advantage/ Premium Options: 🎓 Join the AI Advantage Courses + Community: https://myaiadvantage.com/community 🛒 Discover Work Focused Presets in the Shop: https://shop.myaiadvantage.com/

Оглавление (4 сегментов)

  1. 0:00 Step by step 319 сл.
  2. 1:29 Simple ChatBot 1379 сл.
  3. 7:35 Advance Chatbot 436 сл.
  4. 9:28 Voice Chatbot 1113 сл.
0:00

Step by step

Today, we'll be building a custom ChatGPT chatbot  that works on your iPhone. And not just that,   it will take voice input as we will be  integrating The Whisper API. And as per usual,   no matter your technical level, this  tutorial is going to make the custom   chatbot right on your phone accessible to  everyone. So here's the plan for today:   we'll be building free versions of this. Alright,  the first one is an extremely simple version,   literally everybody can copy-paste this and make  this happen because we'll be using Telegram,   which makes it very simple to integrate this bot. Secondly, we'll make a slightly more complicated   version, also in Telegram, which remembers  your last messages. This is where it starts   getting interesting. And the third  one is the most interesting part of   the video here because it's going to be able  to accept your voice messages. That's right,   you can pick up your phone, record voice messages,  and you're gonna get a reply from ChatGPT.   And not just basic ChatGPT,  you're going to be able to set it up so it   has a personality that you pick in advance.   And all of this can literally be done with   no coding experience whatsoever. But I would  say this, if you're completely new and never   touched code before, I recommend you check out my  last video where I taught you how to install the   app that allows you to run the code. And there I  really start from the ground up and show you how   to use the ChatGPT API as a beginner. Because  today, we'll be building up on our tutorials,   keeping the two basic steps of installing  VS Code and getting your OpenAI API key,   which is still incredibly easy, so  everybody should be able to get that done.   Alright, it's time to get into it. We'll start  on the phone. So for all the free scripts, you'll
1:29

Simple ChatBot

need the Telegram app, so download that first.   Once you've got your account set up, you simply go   to the search and look for BotFather. Alright, now  you open a new chat with this verified account,   and I did this before, and in here it couldn't be  any simpler. All you do is type "/newbot" and then   the BotFather is going to ask you, "Alright, a new  bot. How are we going to call it? Please choose   a name for your bot. " So I'm going to say "AI  Advantage9001". Good, now let's choose a username   for your bot. It must end in "bot" like this, for  example, "Tetrisbot" or "Tetris_bot". So we'll say   "AI_Advantage_9001_bot". For example, Tetrisbot  or Tetris_bot. So, we'll say AI Advantage9001_bot.    Perfect! And it replies with our API key. All  you need to do is copy this message and bring   it over to your laptop because this is one of the  two things we need to make it work. We need the   Telegram API key and we need the OpenAI API key.   Also, what you'll need here is the Python script   that I'm providing to you in the description  below. There's a Dropbox link which makes this   really intuitive for anybody who hasn't dealt  with code before. But I also put this in my   GitHub repo for you more advanced users. All you  gotta do is download this folder, and then all   you need to do is take that folder and drag it  onto Visual Studio Code. Click "Yes" on this,   and then you'll want to open the very first  script, 01_dummy_chatbot. So, this one is named   "dummy" because it only takes one command and  it doesn't remember, but it's a perfect starting   point to explain this. So let's get into it. Okay, so here's the message from my iPhone,   and all I need to do is copy this API key over  here, just like that. And then inside of the   script, all you need to do is go to "Telegram  API Token", and inside of the quotation marks,   you post your Telegram API key. Makes sense?   Now, the next step here is copy-pasting your   OpenAI API key. We went over this in the last  video, but just as a reminder, under this URL,   you can always create a new API key. And yet  again, we copy-paste it into the quotation marks,   right after it says "OpenAI API key". Okay, before we go any further,   I want to give you a quick and super simple  explanation on what's going on in this code. Okay,   so we just talked about the two API keys. This  is just a way to link to the app, so the Telegram   API token allows you to link directly into the  chat inside your Telegram app on your phone,   and the OpenAI API key allows you to interact with  ChatGPT. Above here, as you might already know,   these are the different packages that we're going  to be using. As a beginner, you can also think   about these as presets that make your life really  simple in here. So obviously, with the OpenAI   package to make ChatGPT work, and then also with  the Telegram package which makes it really simple   to connect to custom chats within your phone. Okay, down here we have a function, and this is   just the basic way of interfacing with a chat  inside of your phone. If you want more details   on all of this, you can always find them in  the Telegram API documentation. But all you   need to know is that this function allows you  to send messages inside of Telegram, and this   part is the ChatGPT integration. As I showed you  in the last video, we're using the GPT-3. 5 Turbo   model here because it's the cheapest, and  it's still excellent. Right after content,   you get to define the personality of your bot.   So here, we're saying, "Say that you're a dummy   chatbot and add a silly phrase. " Okay, and  this part down here, you don't really need   to understand. It's just how the Telegram package  functions, roughly speaking. Every few seconds,   it starts polling and looking for new messages,  and if it gets those, it starts interacting and   you get the results you want, which is a text  message communication with the ChatGPT API here.   Alright, so we're almost ready to go here.   All we need to do is go to Terminal > New   Terminal. And now, you might have noticed  that there's this "requirements" file in   here. This file is here just to make it super  simple to install all the packages. And again,   you don't need to understand what's going on  inside of the terminal here. All you need to   do is type "pip install -r requirements. txt". If  you're on a Mac, it might be "pip3 install". Both   of those will be in the description below. And  then when you hit enter, it automatically installs   all the packages, including Telegram and OpenAI. And let's just switch up this part so it says,   "You're a helpful assistant that always  responds with a joke. " Now we define the   personality of ChatGPT, and we're ready to run  this script. So just go up here, press play, and   now the script is running on your computer. Just  remember that if you close this, it's not going   to work anymore because it's running from here. That's it! Our chatbot is running on this machine   right now. So now, if I open up my phone, so  inside of the newest message with the BotFather,   it links to our new bot. So just click the  link at the top here, and at the bottom,   you can start the chat with the brand new chatbot.   Let's just say, "Write me an essay about Borat. "   "Why did the tomato turn red? Because it saw the  salad dressing. " Okay, one of the standard ChatGPT   jokes. And it does that because we said, "You're  a helpful assistant that always responds with a   joke. " So we forced it to respond with a joke.   So you can set this up in any way. Just remember   that this doesn't remember your previous messages.   This is just the most basic setup, but it works.   Okay, and as we're developing custom apps today,  you might need a hosting provider to host your   ideas once they're done. That's why today, I  partnered with a website you should know about:   Hostinger. They make website hosting easy and  provide everything you need to create a stunning   website. With Hostinger, you'll get a free  domain with the shared and cloud hosting plans,   24/7 customer support, and a 30-day money-back  guarantee. They're highly rated on Trustpilot,   Google, and WordPress beginner, so you know you're  in good hands. You can choose from shared, cloud,   and VPS hosting plans. The latest ones are the  ones that can support your apps and help you   launch them online. With their VPS, you can  get full root access, a dedicated IP address,   and much more. All that you need to successfully  host your application. The VPS plans start at its   lowest $3. 99 a month, and with my discount code  'AI Advantage,' you'll get an additional 10%   discount for VPS and all other plans. So don't  forget to use it! The VPS comes with an easy   setup where you can select your preferred server  location, operating system, and even control   panel. And if you're looking for something even  easier, check out their shared hosting plans.    They're optimized for WordPress and come with  a one-click WordPress installer. Together with   Lightspeed web server technology and advanced  case solutions, you can always choose from their   website builder that comes with designer-made  templates and requires no programming knowledge to   create a website. And with 24/7 support from their  team, you'll never feel lost. Over 1. 5 million   website owners trust Hostinger, and with their  30-day money-back guarantee, you can try them   out risk-free. So if you're looking to start or  improve your online presence, give Hostinger a try!    Click the link in the description below to get  started. And now, let's get back to today's video.   So, let's move to the second script here. Zero two  simple chat bot does the same thing as previously,
7:35

Advance Chatbot

but now you'll get to interact with it on an  ongoing basis. Again, you need to update the API   keys in here first for this to work. You can just  copy-paste them from the first script. And as you   can see, this code is a little longer here. And  that's because we have this reply functionality   in here. Other than that, again, you don't really  need to understand this. And we already installed   all the packages. So again, all we need to do  here is press play, and the script is gonna start   running on our local machine. Here, because we use  the Telegram API key that links to this chat, we   can go back in here and do another request. Let's  just do the same, write me an essay about Borat.    Aha! And here, I noticed another joke. So, this  means our first script is still running. So,   you have two options. Honestly, the simplest one  is if you just close VS Code completely and reopen   it. But you could also go in here, and inside the  terminal, you press Ctrl+C on a Mac, enter, and   that's gonna make it stop. But just remember, you  can always just close the app, reopen it, press   play on the second script, and we're back in the  game again, right? "Write me an essay about Borat" I really want that essay. Wait a few seconds. This  is natural. ChatGPT takes a little bit of time.    And there it goes. Isn't this just perfect?   Look at that. The message always starts with   'bot' because that's what we hard-coded in here.   If you look down here, you're gonna see the bold   formatting and the 'bot' text. If you want to  remove or alter that, you can simply take this   part out. And we're gonna remove that. But the  message starts with 'bot' here by default. And   then the ChatGPT responds, 'Borat is a fictional  character created and portrayed by the comedian   Sacha Baron Cohen, yada yada. ' And then we get the  rest of the essay. So again, it worked. And then   if I follow up here with, 'Why is he so popular? '  as the script also remembers the chat history,   you're gonna see that this answer is contextual,  and it talks about Borat has gained a massive   following and become an iconic character because  of his unique comedic style. AKA, it remembers   that we meant Borat without mentioning it in  the last message. This is getting pretty cool,   right? But the next script is really what this is  all about because if you want to show ChatGPT on
9:28

Voice Chatbot

the phone to some people, one of the coolest  things you can do (trust me on this) is make   this third script work. And it's really not  that hard. It looks a little more complicated,   but again, you can just copy-paste  all of this and learn it later.   I do want to say one extra thing about  understanding this code here because I   feel like it's important. And that is, you can  always take this function, copy it into GPT4,   and ask, 'What does this do? ' And it's  going to tell you. And you always have   the ability to follow up with more questions.   And that's how you learn. But for me personally,   my favorite way is just making things work,  somehow getting excited from the results, and   then learning how all the details work. So you can  do the same here. Just open up the third script.    And again, we're gonna need our OpenAI API key  up here, the Telegram API key. Oh, and of course,   if we go into the terminal again, we'll have  to press Ctrl+C to stop the last script from   running because otherwise, the second script  bot would still be active on our phone.   And here we have Super Telegram GPT, a helpful  Telegram bot who is also extremely funny and   very confident and likes to throw people a bit.   Alright, so just like before, this function allows   us to send messages to Telegram and gets us the  ChatGPT response. What is completely new, though,   is this following function. So this is what you  need to send voice messages to the Telegram API.    And it's not just that. Within here hides  one thing that I need you to be aware of,   and that is the so-called Whisper API. Whoa,  a new thing! What is that? Very simple. OpenAI   offers multiple APIs. One of them is the  ChatGPT API. And besides the older GPT-3  API and the newer GPT-4 API, they also have a  completely different product called Whisper,   which is all about speech to text. That means  it takes the words from a sound file and turns   them into a transcript. And then it takes the  transcript and sends it to ChatGPT because ChatGPT   doesn't take voice. It only takes text, right? So again, we allow the Telegram chatbot to accept   your voice. Then we transform the voice into text.   And then we send that text to ChatGPT and get a   text reply. And that is it, kind of. I left out  one thing, which is not essential to understand,   but I want to mention it anyway. And that is when  you record voice messages inside of Telegram,   they come in this dot OGG format, which is just  an alternative to MP3. And Whisper wants MP3s,   which you're probably familiar with. And that's  right here at the top. We had to import the movie   Pi package, which allows us to transform the  OGG to MP3. So really, it's your voice to the   Telegram voice function, which turns it into  OGG. Then we transform that into MP3. That MP3   file of your voice message goes to the Whisper  API, which turns it into text. And then we send   the text to the ChatGPT API, which returns a  text response. Okay, I hope that makes sense.    And if you want to go even deeper, again, open up  the Telegram documentation, or ideally, use GPT4   to dissect this line by line and use the prompt  'Explain this code step by step to a beginner. '  Alright, enough talk, let's do this. Let's press  play on the script and let's see if this works.    'Write me an essay about Borat. ' And here it's set  up to give you a message that lets you know that   it received the voice message. I also included  the line that shows you exactly what the voice   message got translated to for Whisper. In this  case, it's 'Write me an essay about Borat. '   And there you go. 'Borat Sagdiyev, portrayed by  Sacha Baron Cohen, is a fictional character that   has taken the world by storm. ' Perfect, we made it  work. 'How could I be more like Borat? ' And again,   it says, 'I've received a voice message. Please  give me a second to respond. ' 'How could I be   more like Borat? ' And the cool thing is that  if you look at your computer in this terminal,   you'll see all the actions that are happening.   So a second ago, MoviePy was writing   audio/voice_message. mp3. And also, as you'll see  in the folder here above, it saves the different   voice messages that you sent to this bot. And there you go, a bunch of recommendations   on how could I be more like Borat. 'While  Borat's antics might be entertaining to watch,   it's important to remember that his behavior  can often be inappropriate and offensive. ' Yeah,   fair enough, but that's why he's funny, anyway.   So that works. Isn't that incredible? But given   I have to keep my computer open or run this on  my desktop at home, which is my usual workflow,   but now the obvious question presents itself:  how do you go further than this? How can you   make this run 24/7 so this Telegram bot is  operational all the time, independently of   you running VS code on your computer at home? Well, but I fear that goes beyond the scope   of this tutorial. You will need to host  this Python script on a service like AWS,   which is just not beginner-friendly enough  for me to include it in this video. But I'll   include a link in the description below to another  tutorial that explains this really well. But hey,   if you want me to create a tutorial like  that, just leave a comment below. I can do   that too. And with that, I think we got  episode 2 out of 3 in this mini-series   that shows you how to work with the ChatGPT API. I'm currently thinking of making a third episode,   and the idea there is showing you how to  get text-to-speech back from the bot. So you   speak to the bot, and it speaks back. If that's  something you're interested in, leave a comment   below. Otherwise, share your ideas. What other  tutorials would you like to see? And otherwise,   I hope you have a lot of fun with this little  Telegram custom bot. And all I would say is, show   it to your friends, show it to your family. This  is something that 99% of ChatGPT users will never   achieve. So go ahead and use it to your advantage,  and check out the next video. I'll see you there!

Ещё от The AI Advantage

Ctrl+V

Экстракт Знаний в Telegram

Транскрипты, идеи, методички — всё самое полезное из лучших YouTube-каналов.

Подписаться