Create Cute Voiceovers with Baidu TTS and Python

This guide shows how to use Baidu's AI speech synthesis service with Python, covering SDK installation, app creation, obtaining credentials, and sample code to convert text—including daily quotes from an external API—into audio files, even customizing voice styles.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Create Cute Voiceovers with Baidu TTS and Python

During the National Day holiday many elders use voice features in news apps; text‑to‑speech can help them read content without straining their eyes.

Install Baidu SDK

Install the Baidu AI Python SDK via pip, using a faster mirror.

pip3 install baidu-aip -i https://pypi.douban.com/simple/

Create Application

Visit the Baidu TTS page ( https://ai.baidu.com/tech/speech/tts ), log in with a Baidu account, and create a new application. Select only the speech synthesis API if you only need text‑to‑speech. After creation you will obtain three essential credentials: AppID, API Key, and Secret Key.

The application list shows the three keys needed for API calls.

In the documentation you can see the basic request parameters.

Code Debugging

Write a simple script that calls the Baidu TTS API. Fill in the AppID, API Key, and Secret Key you obtained.

from aip import AipSpeech
APP_ID = '输入你的APP_ID'
API_KEY = '输入你的API_KEY'
SECRET_KEY = '输入你的SECRET_KEY'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
# 中文:zh 粤语:ct 英文:en
result = client.synthesis('哈哈哈哈', 'zh', 1, {
    'vol': 5, 'per': 4
})
if not isinstance(result, dict):
    with open('audio.mp3', 'wb') as f:
        f.write(result)

Running the script generates an audio.mp3 file in the current directory.

Add Daily Quotes for a Cute Voice

Use the Jinshan Ciba daily sentence API to fetch an English sentence and its Chinese translation, then let the TTS engine read them, giving the voice a more playful tone.

def get_msg():
    url = 'http://open.iciba.com/dsapi/'  # Jinshan Ciba daily sentence API
    html = requests.get(url)
    content = html.json()['content']  # English sentence
    note = html.json()['note']        # Chinese translation
    return content, note

Replace the fixed text in the previous example with the sentences returned by get_msg(), then run the script to produce a cute voiceover.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonAPItext-to-speechBaidu AI
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.