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.
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.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.