API
The CosyVoice voice cloning service generates a custom voice that is natural-sounding and highly similar to the original speaker, based on a short audio sample. This topic describes the APIs for the CosyVoice voice cloning service.
API call instructions
Configure the following parameters when you call an API:
domain: nls-slp.cn-shanghai.aliyuncs.com
version: 2019-08-19
For more information, see Usage examples.
API details
CosyVoiceClone: Submit a voice cloning task
Description
Submits a voice cloning task. You must specify the sample audio file and a name prefix for the generated audio.
Request parameters
Parameter
Type
Passing parameters
Required
Description
Url
String
Body
Yes
The URL of the sample audio file. Make sure the file is accessible over the public network. You can upload only one audio file at a time. The audio file must meet the following requirements:
Number of sound channels: Mono
Audio bit depth: 16 bit
Sample rate: Greater than 22050 Hz
Format: WAV, MP3, or M4A
Duration: 5 to 20 seconds
VoicePrefix
String
Body
Yes
The prefix for the name of the generated audio file. For example: tongyi.
Request example:
{ "Url": "http://****.oss-cn-hangzhou.aliyuncs.com/linjing/voicegen/dataset/Musk.wav?OSSAccessKeyId=LTAI****************&Expires=3601716441689&Signature=1JLsNxGoGkJE1XTpRJu7yI****", "VoicePrefix": "tongyi" }Response parameters
Parameter
Type
Description
RequestId
String
The request ID.
Code
Integer
The status code.
Message
String
The error message.
VoiceName
String
The name of the generated audio file. The format is `cosyvoice-${voice_prefix}-${7-digit random string}`. `${voice_prefix}` is the prefix for the audio name that you set in the request parameters.
Response example:
{ "RequestId": "A3136B58-5876-4168-83CA-B5627819****", "Code": 20000000, "Message": "SUCCESS", "VoiceName": "cosyvoice-tongyi-90fa79f" }
ListCosyVoice: Query all voices with a specified name prefix
Description
Queries all voices with a specified name prefix. The results are paginated.
Request parameters
Parameter
Type
Parameter passing
Required
Description
VoicePrefix
String
Body
Yes
The prefix of the audio names to query. For example: tongyi.
PageSize
Integer
Body
No
The page size. Default value: 10.
PageIndex
Integer
Body
No
The page number. Default value: 1.
Request example:
{ "VoicePrefix": "tongyi" }Response parameters
Parameter
Type
Description
RequestId
String
The request ID.
Code
Integer
The status code.
Message
String
The error message.
PageIndex
Integer
The current page number.
PageSize
Integer
The size of the current page.
TotalCount
Integer
The total number of voices that have the specified name prefix.
Voices
List
The list of voices.
Voices[i].VoiceName
String
The audio name.
Voices[i].Status
String
Status: The voice cloning status.StatusDesc: The description of the voice cloning status.The mapping is as follows:
If
StatusisSUCCESS,StatusDescis "Cloning successful".If
StatusisOFFLINE,StatusDescis "Offline".
Voices[i].StatusDesc
String
Voices[i].GmtCreate
String
The time when the voice cloning task was created. For example: 2024-06-14 16:20:42.
Response example:
{ "TotalCount": 1, "RequestId": "C623E918-1C7E-137F-BDFE-6E872107****", "Message": "SUCCESS", "PageSize": 10, "PageIndex": 1, "Code": 20000000, "Voices": [ { "Status": "SUCCESS", "StatusDesc": "Cloning successful", "GmtCreate": "2024-06-14 16:20:42", "VoiceName": "cosyvoice-tongyi-0a9a15e" } ] }