Send Voice Message to Telegram Using Raspberry Pi

Telegram text message is quite common, let's try voice message using Raspberry Pi.


There have few Raspberry Pi Telegram tutorials that I have shared before that involve text message such as:

  1. Displaying Telegram Message on Dot Matrix Using Raspberry Pi
  2. Controlling Electrical Appliances Through Telegram Message Using Raspberry Pi

So now I would like to try something new which is voice message. Before that, I recommend you to try the tutorial above as a start for Raspberry Pi Telegram bot application.


This video shows how to send voice message to Telegram using Raspberry Pi.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is python 3 sample program to record voice and send to Telegram. Please edit code at line 39 with your Telegram bot token.

from gpiozero import LED, Buzzer, Button, OutputDevice
from time import time, sleep, strftime
from datetime import datetime
import os
import signal
import telepot
led1 = LED(17)
sw1 = Button(21)
buzzer = Buzzer(26)
def handle(msg):
global telegramText
global chat_id
global telegramMessage
chat_id = msg['chat']['id']
telegramText = msg['text']
print('Message received from ' + str(chat_id))
if telegramText == '/start':
bot.sendMessage(chat_id, 'Welcome to Idris Bot')
buzzer.beep(0.1, 0.1, 2)
telegramMessage = True
def sw1Pressed():
global sw1ButtonPressed
sw1ButtonPressed = True
def sw1Released():
global newSpeechRecord
newSpeechRecord = True
os.system('pkill arecord')
bot = telepot.Bot('YOUR TELEGRAM BOT TOKEN')
print("Telegram bot is ready")
sw1.when_pressed = sw1Pressed
sw1.when_released = sw1Released
telegramMessage = False
sendAudioEnable = False
newSpeechRecord = False
sw1ButtonPressed = False
buzzer.beep(0.1, 0.1, 1)
while True:
if telegramMessage == True:
telegramMessage = False
if telegramText == 'ENABLE':
sendAudioEnable = True
print("Send speech audio is enable.")
bot.sendMessage(chat_id, "Send speech audio is enable.")
if sw1ButtonPressed == True:
sw1ButtonPressed = False
print("Start recording…")
os.system('arecord -D hw:1,0 -f cd record.wav -c 1')
if newSpeechRecord == True and sendAudioEnable == True:
newSpeechRecord = False
print("Send audio to Telegram.")
bot.sendAudio(chat_id, audio=open('record.wav', 'rb'))
except KeyboardInterrupt:

Thank You


  1. Using Telegram Bot with Raspberry Pi: Sharing Text and Files
  2. To use USB mini microphone on Raspbian

Thanks for reading this tutorial. If you have any technical inquiry, please post at Cytron Technical Forum.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

BLTouch Installation for Ender 3 with 32-bit V4.2.2 Board
Pick and Send Random Meal’s Option and Locations through Telegram Bot Using Grove WiFi 8266 on micro:bit
DIY Automated Vacuum Cleaner Using REKA:BIT With Micro:bit
Rainbow Spark in Mini House using Maker Uno.
TinyML on Arduino using Edge Impulse
Tutorials of Cytron Technologies Scroll to Top