Building a Vietnamese Voicebot in 1 Hour: Integrating STT, LLM and TTS APIs with Python

Learn how to build a responsive Vietnamese voicebot in 60 minutes. This guide covers integrating STT, LLM, and TTS APIs using Python for real-time speech AI.

Deploying an automated voice assistant for a business is often perceived as complex because it requires the synchronous orchestration of three distinct components: speech recognition, semantic reasoning, and speech synthesis. This article provides a practical guide to building a Vietnamese voicebot in Python, helping you integrate AI voice APIs and create a stable Vietnamese voicebot tutorial that works effectively within 60 minutes.

Why Choose Python for Voicebots?

Python is the most popular language in the AI field due to its rich library ecosystem and readable syntax. When working with modern APIs, Python allows you to focus on business logic rather than system-level performance concerns. Specifically, for Vietnamese users, having a Natural Language Processing (NLP) and Automatic Speech Recognition (ASR) toolkit optimized for the Vietnamese language is a critical factor in ensuring the voicebot understands context correctly and pronounces words naturally.

AIVISION provides speech AI solutions focused on Vietnamese, having been deployed for hundreds of enterprises in Vietnam and internationally. Using these APIs eliminates the need for complex model training; you simply call the API to receive accurate results.

Overview of Voicebot Architecture

A standard voicebot operates through a sequential processing chain:

  1. Input: Capture audio from the user.
  2. STT (Speech-to-Text): Convert audio into text.
  3. LLM (Large Language Model): Process the text, reason, and generate a response.
  4. TTS (Text-to-Speech): Convert the response into audio for the speaker.

To effectively integrate AI voice APIs, you must ensure low latency at each step. Below are the specific steps for implementation.

Step 1: Prepare the Environment and API Keys

Install the necessary libraries:

pip install requests websocket-client python-dotenv

Create a .env file to store your API Key:

AIVISION_API_KEY=your_api_key_here

Step 2: Integrate STT - Vietnamese Speech Recognition

The most critical part of building a Vietnamese voicebot in Python is the ability to recognize Vietnamese accurately. AIVISION Speech-to-Text supports both real-time streaming via WebSocket and file processing via REST. For a voicebot to respond quickly, we will use streaming mode.

Here is a sample Python code snippet to connect via WebSocket and send audio:

import websocket
import json
import base64

def on_message(ws, message):
  data = json.loads(message)
  if 'text' in data:
  print("STT Result:", data['text'])

ws = websocket.WebSocketApp(
  "wss://api.s2speech.com/v1/stt/stream",
  on_message=on_message
)
ws.run_forever()

Note: When capturing audio, ensure the sample rate matches the API requirements (typically 16kHz for good voice quality).

Step 3: Semantic Processing with an LLM

Once you have the text from the STT step, you need a "brain" to understand the user's intent. AIVISION provides aivision-L1.0, a large language model that supports both Vietnamese and English with streaming output capabilities.

import requests
import os

def get_llm_response(user_text):
  url = "https://api.s2speech.com/v1/chat/completions"
  headers = {
  "Authorization": f"Bearer {os.getenv('AIVISION_API_KEY')}",
  "Content-Type": "application/json"
  }
  payload = {
  "model": "aivision-l1",
  "messages": [
  {"role": "system", "content": "You are a friendly virtual assistant. Answer concisely in Vietnamese."},
  {"role": "user", "content": user_text}
  ],
  "stream": True
  }
 
 # Process stream response for faster replies
  with requests.post(url, headers=headers, json=payload, stream=True) as response:
  for line in response.iter_lines():
  if line:
  yield line.decode('utf-8')

Step 4: Synthesize Speech with TTS

The final step is converting the response into speech. AIVISION TTS (aiv-tts-S.1.0) supports natural Vietnamese pronunciation, particularly excelling at reading English words interspersed within Vietnamese sentences fluently. This strength ensures the voicebot does not "stumble" when encountering technical terms.

def text_to_speech(text):
  url = "https://api.s2speech.com/v1/tts"
  headers = {
  "Authorization": f"Bearer {os.getenv('AIVISION_API_KEY')}",
  "Content-Type": "application/json"
  }
  payload = {
  "model": "aiv-tts-s1",
  "input": text,
  "voice": "female-vn", # Select Vietnamese female voice
  "response_format": "mp3"
  }
 
  response = requests.post(url, headers=headers, json=payload)
  if response.status_code == 200:
 # Save audio file or stream directly
  return response.content

Comparison of Integration Methods

Component REST (File) Method WebSocket (Stream) Method Suitable Application
STT Simple, processes recorded files Real-time, low latency Text chatbot / Real-time voicebot
LLM Receives full response Streams word-by-word, better UX Virtual assistant, Callbot
TTS Creates MP3/WAV file Streams audio directly Smart speakers, Telephony

Tips for a Smooth Voicebot Experience

  1. Concurrency: Do not wait for STT to finish before calling the LLM, and do not wait for the LLM to finish before calling TTS. Use threads or async processing to run the pipeline in parallel. For example, as the LLM streams out the first sentences, you can immediately start sending those segments to TTS.
  2. Latency Optimization: For a voicebot, users expect a response within 1-2 seconds. Prioritize APIs that support streaming.
  3. Exception Handling: Always have a fallback mechanism for API errors or network instability. For instance, if STT fails to recognize speech, politely ask the user to repeat.
  4. Multi-Regional Testing: Vietnamese has many local dialects. Test the voicebot with different accents to ensure accuracy.

AIVISION has assembled a 690,517-hour Vietnamese speech corpus and trained its models on powerful GPU infrastructure, helping them achieve high accuracy on independent test sets. Using these APIs allows you to leverage this technological quality without investing in complex AI infrastructure.

Conclusion

Building a Vietnamese voicebot in Python is no longer a difficult task if you have the right tools. By integrating AI voice APIs from AIVISION, you can create a complete Vietnamese voicebot tutorial that operates smoothly and accurately. The process above is just a foundation; you can extend it with features such as user authentication, CRM integration, or scheduling systems.

Start experimenting today. You can sign up to try AIVISION’s APIs for free and explore the potential of voice AI for your product.

If you need technical support or solution consulting, please Contact our technical team directly. You can also refer to other AI articles on our Blog.

Start free to begin your voicebot building journey now.

Frequently asked questions

Do I need deep Machine Learning knowledge to build a voicebot?

Not necessarily. You only need to know how to call REST and WebSocket APIs. AIVISION has packaged the entire AI model, so you can focus solely on the business logic of your voicebot.

Can a Vietnamese voicebot read English words?

Yes. AIVISION TTS supports reading English words interspersed in Vietnamese sentences naturally, helping the voicebot handle technical terms or proper nouns effectively.

Does voicebot latency affect user experience?

Yes. High latency makes conversations feel hesitant. Using APIs that support streaming for both STT and TTS is the best way to minimize latency and create an instant response feel.

Can I customize the TTS voice?

Yes. AIVISION supports voice cloning, allowing you to create a unique voice from 20 seconds to 2 minutes of recorded audio (with the person's consent), giving the voicebot a distinctive and friendly tone.

What is the cost to run this voicebot?

AIVISION provides a free trial for every account with a daily usage limit. You do not need a payment card to start. For large-scale enterprise needs, you can contact us to have your usage limit raised.

Try AIVISION's Vietnamese speech AI

Speech-to-Text, Text-to-Speech and LLM, free.

Start free → Contact

By

Dr. Giang Vo — CEO, AIVISION

Dr. Giang Vo is the CEO of AIVISION, leading the development of s2speech — speech recognition, AI voices and a large language model for Vietnamese — and working with companies at home and abroad on their deployments.

0981 419 967 · giang.vo@aivgroups.com

#Vietnamese voicebot#Python speech AI#STT API#LLM integration#TTS API#AIVISION#real-time voice assistant

Related articles