Single-Speaker Speech Generation
Synthesize a piece of text into speech with a single voice, suited to narration, customer-service scripts, announcements, and audio content generation.
Workflow
POST /v1/audio/speech
Endpoint
moss-tts
Model
Create an API Key
Open the API Key management platform, create an API Key, and save it as an environment variable. Do not write the API Key into client-side code or commit it to a repository.
Example export MOSS_API_KEY="<your-api-key>"Prepare the request input
Use
modelto specify the model, and fill in the input fields required for single-speaker speech synthesis. For a reference voice, first create one withPOST /v1/audio/voices, then use the resultingvoice_idhere.input: text to synthesize voice or voice_id: target voice response_format: output format, defaults to mp3 delivery_method: audio or url
request.json { "model": "moss-tts", "input": "Welcome to the MOSI speech synthesis service. This is a sample voiceover.", "voice_id": "<voice_id>", "response_format": "mp3", "delivery_method": "url" }Send the first request
Send a request to
POST /v1/audio/speech. Whendelivery_method=url, JSON and a result URL are returned synchronously.curl https://api.mosi.cn/v1/audio/speech \ -H "Authorization: Bearer $MOSS_API_KEY" \ -H "Content-Type: application/json" \ -d @request.jsonRetrieve the result
When
delivery_method=url, read the result URL from the JSON of the synchronous response. If you passasync=true, the endpoint first returns atask_id, which you then use to query the task.curl https://api.mosi.cn/v1/audio/tasks/$TASK_ID \ -H "Authorization: Bearer $MOSS_API_KEY"Verify success
Success indicator: you obtain the result audio (
delivery_method=audio) or a result URL (delivery_method=url), and can download or play the generated audio.