Telegram Bot for Learning Japanese

Tech Stack:
Python Telegram Bot OpenAI TTS ElevenLabs

A Telegram bot that uses OpenAI to teach users Japanese expressions, grammar, kanji, and speaking intonation.

Telegram Bot for Learning Japanese

Project Overview

I was learning Japanese from a mobile application. The app is good for learning a new vocabulary and grammar. However, when I had questions or wanted to hear how natives would pronounce certain expressions, I couldn’t find any easy-to-use tools that fit my needs. That’s why I decided to develop my own version using a Telegram bot as the interface and ElevenLabs as the Text-to-Speech service.

Overall the bot is not a conversational bot. It is more like a language learning assistant.

Tech Stack

  • Python Telegram Bot
  • Pydantic AI
  • ElevenLabs for TTS

Key Challenges

  1. Figuring out how to make the AI act as a Japanese language teacher and return effective information to the learner
  2. Ensuring that only Japanese text would be converted to audio, not all messages

Solutions

  1. Implementing prompt engineering
Your name is Satoshi. You are a helpful assistant that can help with Japanese learning.

You will reply user in Japanese language along with romaji and translate in Bahasa Indonesia
i.e.
おはよう (ohayou)
Selamat pagi

You will help users with learning Japanese especially when they ask for:
- Translation of user input into Japanese language expressions
- Explanation of grammar patterns
- Learning Kanji

IMPORTANT: When providing responses, you must include:
1. content: The complete Japanese text with proper kanji, katakana, and hiragana
2. hiragana_only: The same content but written entirely in hiragana characters (convert any kanji to hiragana)
3. romaji: The romanized version
4. bahasa_indonesia: Indonesian translation
5. more_detail: Additional explanations if needed

Example:
content: "今日は晴れです" (complete form with kanji)
hiragana_only: "きょうははれです" (same content in hiragana only)
romaji: "kyou wa hare desu"
bahasa_indonesia: "Hari ini cerah"
  1. Using Pydantic AI and schema

Pydantic is a popular Python library for handling form or input schema in web development. The Pydantic schema works well with the Pydantic AI library that I use for invoking the LLM model. Below is how the schema looks like. It makes the AI response in structured output according to the schema. The hiragana_only content is sent to ElevenLabs TTS, allowing users on the Telegram bot to hear how the hiragana is pronounced by a native speaker.

from pydantic import BaseModel, Field
from typing import Optional


class JapaneseResponse(BaseModel):
    """Schema for Japanese learning bot response with structured output."""

    content: str = Field(
        description="The main Japanese content/text response", examples=["こんにちは"]
    )

    hiragana_only: str = Field(
        description="The same content written only in hiragana characters",
        examples=["こんにちは"],
    )

    romaji: str = Field(
        description="Romanized version of the Japanese content", examples=["konnichiwa"]
    )

    bahasa_indonesia: str = Field(
        description="Indonesian translation of the content", examples=["Halo"]
    )

    more_detail: Optional[str] = Field(
        default=None,
        description="Additional details, explanations, or context if needed",
        examples=["This is a common greeting used throughout the day"],
    )

Lessons Learned

  • I learned how to use Pydantic AI to create a schema for the structured output.
  • I learned how to implement ElevenLabs TTS to convert text to speech especially for speaking Japanese.

Attachements

Telegram Bot Example Chat

Link to the bot: SathosiNihonBot