Based on the Volcano Engine Doubao speech synthesis WebSocket protocol (PodcastTTS,/api/v3/sami/podcasttts) synthesize a certain topic into podcast audio and save it as a local file. Supports:
- Input a topic sentence or a web page address (it can also be a file download address, supporting pdf/word/txt formats) to generate a podcast
- Output the podcast audio download link
- Output the podcast segmented text (JSON)
Applicable scenarios
- The user mentions
生成播客or播客合成and other related keywords. - The user needs to generate a podcast-format audio file for a certain topic.
- The user needs to generate a podcast-format audio file from the content of a certain web page or file.
- The user needs to generate a podcast-format audio file from the content of a file uploaded by the user or from a long context.
Usage steps
- Analyze the content for which the user needs to synthesize a podcast, and prepare the input to be synthesized:
prompt_text(the original topic, generally no more than 20 characters) orinput_url(web page address or file download address) ortext(content read from a file uploaded by the user or a relatively long text, generally more than 200 characters). - Before running the script, first
cdto this skill directory:skills/byted-podcast-gen。 - Configure authentication (environment variables or command-line arguments).
- Run the script:
python scripts/podcast.py [参数]. Refer to the examples section below. - According to the
audio_path/texts/audio_urlin the JSON output by the script, use the generated result. If there isaudio_urlwhich is a URL with an expiration time, it can be returned to the user,audio_pathis a local file path, which can be provided to the user for download.
Environment variables and authentication
This script authenticates through WebSocket Header. You can pass it in via command-line arguments, or configure environment variables (recommended, to avoid leaking credentials in command-line history):
- Required:
MODEL_SPEECH_API_KEY
Script parameters
| Parameter | Short form | Required | Description |
|---|---|---|---|
--text |
No | Input the original long text (used whenaction=0 ) |
|
--input_url |
No | URL of the input text (used whenaction=0 , choose one of the two) |
|
--prompt_text |
No | Prompt text (required whenaction=4 ) |
|
--action |
No | Podcast type:0(original text/URL),4(prompt); default 4 |
|
--speaker_info |
No | Speaker configuration JSON (default {"random_order":false}) |
|
--encoding |
No | Audio format:mp3(default),wav、ogg_opus |
|
--output |
No | Final audio output file path (by default automatically generated to output/) |
Return value description
The script outputs JSON, including:
status:"success"or"error"task_id: task identifier (used to locate a generation task)audio_path: final audio local pathtexts: segmented text JSON string, the text list corresponding to each speaker.audio_url: the audio download address returned by the servererror: error message on failure
Error handling
- If an error is reported indicating that
MODEL_SPEECH_API_KEYis missing: check whether the environment variable or command-line argument has been configured. If it does not exist, prompt the user for input, then set it in the environment variable. - If a server-side error is received (
MsgType.Error): based on the error message, check account permissions, the resource ID, the input content, and whether the service has been activated. - If the server-side error received contains the keyword
quota, it indicates that the current account has exceeded the quota and needs to upgrade the Volcano Engine Doubao Speech podcast service. - When python execution is missing related packages, the dependencies need to be installed first:
pip install -r requirements.txt
Reference documentation
Example
# 基于话题生成播客音频
ptompt_text="豆包语音合成服务"
python scripts/podcast.py --prompt_text $ptompt_text --action 4
# 基于网页内容生成播客音频
url="https://www.volcengine.com/docs/6561/1668014?lang=zh"
python scripts/podcast.py --input_url $url --action 0
# 基于长文本内容生成播客音频
text="欢迎收听本期节目,我们聊聊人工智能的关键拐点……"
python scripts/podcast.py --text $text --action 0