跳转至

MaaS-nar

MaaS-nar shortTextToSpeech

请求方法

POST

请求路径

/tts-n/text-to-speech/{responseFormat}

路径变量

参数 描述 示例
responseFormat 语音格式 mp3/m4a mp3

请求参数

参数 描述 示例
voice 声音
可选值
Yifei
voice-speed 语速
可选值
fast
normal
slow
数字0.3-2之间
normal
voice-volume 音量
可选值
x-loud
loud
standard
soft
x-soft
normalized
loud
参数 描述 示例
Accept 固定值application/octet-stream application/octet-stream
Authorization AccessKey
Bearer ${AccessKey}
Bearer RWYhq1NsLPAMmieux0Gd
Content-type 可选值
text/plain
application/application/x-www-form-urlencoded
text/vtt
application/x-subrip
text/srt
text/plain

请求body格式和header中Content-type需要对应

请求body

注意Content-type和body格式的对应

  • body传UTF-8字符串

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Accept: application/octet-stream' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-type: text/plain' \ --data 'hello'

  • body传urlEncode过后的字符串

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Accept: application/octet-stream' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data '%E4%BD%A0%E5%A5%BD%E5%95%8A'

  • body传UTF-8的文本文件脚本

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Accept: application/octet-stream' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-type: text/plain' \ --data '@test.txt'

  • body传VTT文件

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Accept: application/octet-stream' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-Type: text/vtt' \ --data '@sing-song_2024-07-29_103928.vtt'

  • body传SRT文件

    方式一 curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Accept: application/octet-stream' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-Type: application/x-subrip' \ --data '@sing-song_2024-07-29_103928.srt'

    方式二 curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Accept: application/octet-stream' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-Type: text/srt' \ --data '@sing-song_2024-07-29_103928.srt'

返回值header

参数 描述 示例
x-duration-seconds 语音时长(秒) 3

返回值

文件流

MaaS-nar longTextToSpeech

调用链路

  1. 调用longTextToSpeech的接口获取到statusUrl
  2. 通过轮询请求statusUrl(建议5-10s一次)获取任务结果
  3. 如果获取到任务结束并且成功,通过返回值中result里的url下载音频

请求方法

POST

请求路径

/tts-n/text-to-speech/{responseFormat}

pathVariables

参数 描述 示例
responseFormat 语音格式 mp3/m4a/wav wav

queryParams

参数 描述 示例
voice 声音
可选值
Yifei
voice-speed 语速
可选值
fast
normal
slow
数字0.3-2之间
normal
voice-volume 音量
可选值
x-loud
loud
standard
soft
x-soft
normalized
loud

请求header

参数 描述 示例
Authorization AccessKey
Bearer ${AccessKey}
Bearer RWYhq1NsLPAMmieux0Gd
Content-type 可选值
text/plain
application/application/x-www-form-urlencoded
text/vtt
application/x-subrip
text/srt
text/plain

不要设置Acceptheader

请求body格式和header中Content-type需要对应

请求body

注意Content-type和body格式的对应

  • body传UTF-8字符串

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-type: text/plain' \ --data 'hello'

  • body传urlEncode过后的字符串

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data '%E4%BD%A0%E5%A5%BD%E5%95%8A'

  • body传UTF-8的文本文件脚本

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-type: text/plain' \ --data '@test.txt'

  • body传VTT文件

    curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-Type: text/vtt' \ --data '@sing-song_2024-07-29_103928.vtt'

  • body传SRT文件

    方式一 curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-Type: application/x-subrip' \ --data '@sing-song_2024-07-29_103928.srt'

    方式二 curl --location 'https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/tts-n/text-to-speech/mp3' \ --header 'Authorization: Bearer ${AccessKey}' \ --header 'Content-Type: text/srt' \ --data '@sing-song_2024-07-29_103928.srt'

返回值

参数 描述 示例
statusUrl 用于获取任务执行结果的url,可以直接通过get请求,不需要授权信息,建议5-10s获取一次
taskId 任务id 1

通过statusUrl获取结果

字段 描述 类型
finished 任务是否结束。true 代表应停止轮询 Boolean
percent 0-100之间,音频生成进度 Integer
succeeded 音频是否生成成功 Boolean
result 音频生成成功后下载音频的url,有效期为 10 分钟 String
message 音频生成失败的原因 String
durationInSeconds 音频时长,单位为秒,四舍五入到最近的整数秒。 Integer