Dive into the world of dynamic user interaction with our Python script — a Telegram bot that seamlessly integrates various APIs to elevate the chatbot experience.
It is both:
Text to Speech (TTS) Bot
Speech to Speech (STS) Bot
Scripting Language : Python
Platforms used : Telegram, ChatGPT, OpenAI(Whisper), Eleven Labs
This Python script encompasses functionalities from Telegram, OpenAI (Whisper), Eleven Labs, and more, creating a sophisticated chatbot that responds to both text and voice messages. (Text to Speech (TTS) & Speech to Speech (STS) )
Key Functionalities:
Telegram API Integration:
Utilizes the telebot library to interact with the Telegram API.
Responds to '/start' and '/help' commands with a warm welcome message.
OpenAI API Integration (Whisper):
Processes text and voice messages from users.
Converts voice messages to text [Speech to Text (STT)] using the OpenAI Whisper API.
Utilizes ChatGPT from OpenAI to generate responses based on the entire conversation history.
Conversation Logging:
Logs user interactions by appending messages to user-specific log files.
Maintains a comprehensive history of the conversation, including both user and bot messages.
Text-to-Speech (TTS) with Eleven Labs API:
Converts generated text responses into voice messages using the Eleven Labs text-to-speech (TTS) API.
Sends voice messages back to users through the Telegram platform.
Error Handling:
Implements robust error handling to manage exceptions during the process.
Sends informative error messages back to users through the Telegram bot.
Continuous Polling:
Ensures seamless interaction by using bot.polling(none_stop=True) to continuously check for new messages from Telegram users.
Configuration:
Requires API tokens (Telegram, OpenAI, and Eleven Labs) and other parameters, set at the beginning of the script.
Additional Notes:
Some sections of the code are commented out, indicating potential areas for future implementation.
Debug information is printed during the process for easier troubleshooting.
What more can be done:
OCR functionality can be added to this using Google Cloud Vision
Make.com automations & Zapier Automations can be built upon this
Impactful User Experience:
This script effectively combines the capabilities of Telegram, OpenAI, and Eleven Labs APIs to create an interactive chatbot. Users can engage in a conversation using both text and voice messages, receiving text-based responses and even enjoying voice messages in return. The seamless integration of these APIs enhances the overall user experience, making the chatbot dynamic, responsive, and truly interactive.
Comments