tts-api.yaml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. openapi: 3.0.3
  2. info:
  3. title: AI Voice Synthesis API
  4. description: |
  5. Standardized TTS API for AI assistants (Coze, Dify, GPTs, custom Agents).
  6. Supports sync/async modes, natural language instructions, smart voice recommendation.
  7. version: 1.0.0
  8. contact:
  9. name: AI Voice Team
  10. email: api@your-domain.com
  11. servers:
  12. - url: https://api.your-domain.com
  13. description: Production
  14. - url: https://api-staging.your-domain.com
  15. description: Staging
  16. tags:
  17. - name: voices
  18. description: Voice management
  19. - name: tts
  20. description: Speech synthesis
  21. - name: tasks
  22. description: Async tasks
  23. paths:
  24. /v1/tts/voices:
  25. get:
  26. tags: [voices]
  27. summary: List available voices
  28. security:
  29. - bearerAuth: []
  30. responses:
  31. '200':
  32. description: Success
  33. content:
  34. application/json:
  35. schema:
  36. $ref: '#/components/schemas/VoiceListResponse'
  37. /v1/tts/detect:
  38. post:
  39. tags: [tts]
  40. summary: Smart detect (recommend voice + emotion)
  41. description: AI assistants should call this before synthesize
  42. security:
  43. - bearerAuth: []
  44. requestBody:
  45. required: true
  46. content:
  47. application/json:
  48. schema:
  49. $ref: '#/components/schemas/DetectRequest'
  50. responses:
  51. '200':
  52. description: Success
  53. content:
  54. application/json:
  55. schema:
  56. $ref: '#/components/schemas/DetectResponse'
  57. /v1/tts/synthesize:
  58. post:
  59. tags: [tts]
  60. summary: Sync synthesis (short text, less than 500 chars)
  61. security:
  62. - bearerAuth: []
  63. requestBody:
  64. required: true
  65. content:
  66. application/json:
  67. schema:
  68. $ref: '#/components/schemas/SynthesizeRequest'
  69. responses:
  70. '200':
  71. description: Success
  72. content:
  73. application/json:
  74. schema:
  75. $ref: '#/components/schemas/SynthesizeResponse'
  76. /v1/tts/async-synthesize:
  77. post:
  78. tags: [tts, tasks]
  79. summary: Async synthesis (long text)
  80. security:
  81. - bearerAuth: []
  82. requestBody:
  83. required: true
  84. content:
  85. application/json:
  86. schema:
  87. $ref: '#/components/schemas/AsyncSynthesizeRequest'
  88. responses:
  89. '202':
  90. description: Task accepted
  91. content:
  92. application/json:
  93. schema:
  94. $ref: '#/components/schemas/AsyncSynthesizeResponse'
  95. /v1/tts/tasks/{task_id}:
  96. get:
  97. tags: [tasks]
  98. summary: Query task status
  99. security:
  100. - bearerAuth: []
  101. parameters:
  102. - name: task_id
  103. in: path
  104. required: true
  105. schema:
  106. type: string
  107. responses:
  108. '200':
  109. description: Success
  110. content:
  111. application/json:
  112. schema:
  113. $ref: '#/components/schemas/TaskResponse'
  114. /v1/tts/instruct:
  115. post:
  116. tags: [tts]
  117. summary: Natural language instruction synthesis
  118. description: |
  119. AI assistant describes requirements in natural language
  120. (e.g. "Use magnetic male voice, sad tone"), backend parses params and generates audio.
  121. security:
  122. - bearerAuth: []
  123. requestBody:
  124. required: true
  125. content:
  126. application/json:
  127. schema:
  128. $ref: '#/components/schemas/InstructRequest'
  129. responses:
  130. '200':
  131. description: Success
  132. content:
  133. application/json:
  134. schema:
  135. $ref: '#/components/schemas/InstructResponse'
  136. components:
  137. securitySchemes:
  138. bearerAuth:
  139. type: http
  140. scheme: bearer
  141. bearerFormat: JWT
  142. schemas:
  143. Voice:
  144. type: object
  145. properties:
  146. id: { type: string, example: male-qn-jingying }
  147. name: { type: string, example: Magnetic Male Voice }
  148. gender: { type: string, enum: [male, female, neutral] }
  149. age: { type: string, enum: [child, young, middle, old] }
  150. style:
  151. type: array
  152. items: { type: string }
  153. language: { type: string, example: zh-CN }
  154. preview_url: { type: string, format: uri }
  155. description: { type: string }
  156. VoiceListResponse:
  157. type: object
  158. properties:
  159. code: { type: integer, example: 0 }
  160. message: { type: string }
  161. data:
  162. type: object
  163. properties:
  164. voices:
  165. type: array
  166. items: { $ref: '#/components/schemas/Voice' }
  167. DetectRequest:
  168. type: object
  169. required: [text]
  170. properties:
  171. text:
  172. type: string
  173. minLength: 10
  174. maxLength: 5000
  175. DetectResponse:
  176. type: object
  177. properties:
  178. code: { type: integer }
  179. data:
  180. type: object
  181. properties:
  182. voice_id: { type: string }
  183. voice_name: { type: string }
  184. emotion:
  185. type: string
  186. enum: [neutral, happy, sad, angry, fearful, surprised, disgusted]
  187. emotion_label: { type: string }
  188. scene: { type: string }
  189. role: { type: string }
  190. instruct_text: { type: string }
  191. SynthesizeRequest:
  192. type: object
  193. required: [text]
  194. properties:
  195. text: { type: string, minLength: 10, maxLength: 500 }
  196. voice_id: { type: string }
  197. emotion: { type: string, enum: [neutral, happy, sad, angry, fearful, surprised, disgusted] }
  198. speed: { type: number, minimum: 0.5, maximum: 2.0, default: 1.0 }
  199. pitch: { type: integer, minimum: -12, maximum: 12, default: 0 }
  200. volume: { type: integer, minimum: 0, maximum: 100, default: 50 }
  201. format: { type: string, enum: [mp3, wav, pcm], default: mp3 }
  202. sample_rate: { type: integer, enum: [16000, 24000, 48000], default: 24000 }
  203. SynthesizeResponse:
  204. type: object
  205. properties:
  206. code: { type: integer }
  207. data:
  208. type: object
  209. properties:
  210. audio_url: { type: string, format: uri }
  211. duration: { type: number }
  212. characters: { type: integer }
  213. cached: { type: boolean }
  214. request_id: { type: string }
  215. AsyncSynthesizeRequest:
  216. allOf:
  217. - $ref: '#/components/schemas/SynthesizeRequest'
  218. - type: object
  219. properties:
  220. text:
  221. type: string
  222. minLength: 10
  223. maxLength: 100000
  224. instruction: { type: string }
  225. callback_url: { type: string, format: uri }
  226. metadata:
  227. type: object
  228. additionalProperties: true
  229. AsyncSynthesizeResponse:
  230. type: object
  231. properties:
  232. code: { type: integer }
  233. data:
  234. type: object
  235. properties:
  236. task_id: { type: string }
  237. estimated_duration: { type: integer }
  238. status_url: { type: string }
  239. created_at: { type: string, format: date-time }
  240. TaskResponse:
  241. type: object
  242. properties:
  243. code: { type: integer }
  244. data:
  245. type: object
  246. properties:
  247. task_id: { type: string }
  248. status:
  249. type: string
  250. enum: [pending, processing, completed, failed]
  251. progress: { type: integer, minimum: 0, maximum: 100 }
  252. audio_url: { type: string, format: uri }
  253. duration: { type: number }
  254. characters: { type: integer }
  255. error: { type: string }
  256. completed_at: { type: string, format: date-time }
  257. metadata:
  258. type: object
  259. additionalProperties: true
  260. InstructRequest:
  261. type: object
  262. required: [text, instruction]
  263. properties:
  264. text: { type: string, minLength: 10, maxLength: 5000 }
  265. instruction:
  266. type: string
  267. example: Use magnetic male voice, sad tone, last sentence slow
  268. InstructResponse:
  269. type: object
  270. properties:
  271. code: { type: integer }
  272. data:
  273. type: object
  274. properties:
  275. parsed_params:
  276. type: object
  277. properties:
  278. voice_id: { type: string }
  279. emotion: { type: string }
  280. speed: { type: number }
  281. pitch: { type: integer }
  282. audio_url: { type: string, format: uri }
  283. duration: { type: number }