Artificial Intelligence 8 min read

Building a Python Voice Synthesis System Using Xunfei WebAPI

This tutorial explains how to create a Python-based speech synthesis tool by installing required packages, configuring Xunfei Open Platform credentials, implementing a Tkinter GUI, and using WebSocket communication to convert text into audio with selectable voice profiles.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Building a Python Voice Synthesis System Using Xunfei WebAPI

Background: The author is interested in voice synthesis and wants to build a tool that can read e‑books aloud.

System Overview: By leveraging Xunfei Open Platform's WebAPI, a lightweight voice synthesis system is constructed, reducing development complexity to a few API calls.

Prerequisites: Install Anaconda, Python 3.7, and Visual Studio Code on the development machine.

Steps: Create an application on the Xunfei console, obtain APPID, APIKey, and APISecret, then install the required Python libraries with pip install websocket-client and pip install playsound .

Implementation: Define a class play containing initialization, play_sound , select_vcn , and xfyun_tts methods; set up a Tkinter GUI with text box, voice‑selection combobox, and control buttons.

Core TTS Logic: The Ws_Param class configures business and common arguments, generates an HMAC‑SHA256 signature, builds the authenticated WebSocket URL, and provides callbacks ( on_message , on_error , on_close , on_open ) to handle streaming audio data, saving PCM files and converting them to WAV.

Final Result: The completed application allows users to input text, choose from several voice profiles, synthesize speech via Xunfei's service, and play the generated audio directly from the GUI.

GUIWebSocketSpeech Synthesistext-to-speechXunfei API
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login 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.