You need to enable JavaScript to run this app.
导航

自动字幕打轴

最近更新时间2023.09.18 19:19:36

首次发布时间2022.10.31 17:19:48

1. 流程简介

自动字幕打轴功能整体处理流程分为三个阶段:

  1. 客户端抽取视频中音轨,转成音频文件;
  2. 把音频文件和字幕文本发送至后端集群,获取任务 ID;
  3. 通过任务 ID 访问后端接口获取结果。

非阻塞查询流程

alt

阻塞查询流程

alt

2. 鉴权

设置鉴权内容,请参考鉴权方法

3. 提交音频

3.1 请求

请求地址:http://openspeech.bytedance.com/api/v1/vc/ata/submit
请求方式:HTTP POST

3.1.1 音频二进制请求方式

Header 需要加入内容类型标识:

Content-Type: audio/wav

Url 参数如下所示:

字段
说明
是否必填
备注
appid应用标识用于标识当前应用。
caption_type字幕识别类型speech(说话)或 singing(唱歌)。
audio_text音频字幕文本用于打轴的字幕文本

sta_punc_mode

打轴服务标点模式

默认值为'1'(省略打轴结果句级别末尾逗号句号)
可选'2'(省略打轴结果句级别某些标点,使用空格代替)
可选'3'(保留原文本完整标点)

caption_category字幕输出模式2(固定传入值)
cluster请求集群ata_cluster(固定传入值)

Body 直接传输音频二进制数据

请求示例:

POST /api/v1/vc/ata/submit?appid=your_appid&caption_type=speech HTTP/1.1
Host: openspeech.bytedance.com
Content-Type: multipart/form-data;boundary="boundary"

--boundary
Content-Disposition: form-data; name="data"; filename="talk.wav"
Content-Type: audio/wav
--boundary
Content-Disposition: form-data; name="audio-text"

hello world
--boundary--

3.1.2 音频地址请求方式

Header 需要加入内容类型标识:

Content-Type: application/json

Url 参数同上。
Body 为 JSON 格式字符串,参数如下所示:

字段
说明
是否必填
备注
url音频地址用于标识当前应用。

请求示例:

POST /api/v1/ata/submit?appid=your_appid&caption_type=speech HTTP/1.1
Host: openspeech.bytedance.com
Content-Type: application/json
Connection: keep-alive
Content-Length: xxxxx

{
    "url":"http://xxx.com/talk.wav",
    "audio_text": "hello world",
}

3.2 应答

应答格式: JSON

应答字段:

字段
说明
层级
格式
是否必填
备注
code状态码1int0 为成功,非 0 为失败。
message状态信息1string失败时标记失败原因。
id任务 ID1string仅当提交成功时填写。

应答示例:

{
    "code": "0",
    "message": "Success",
    "id": "fc5aa03e-6ae4-46a3-b8cf-1910a44e0d8a"
}

4. 查询结果

4.1 请求

请求地址:http://openspeech.bytedance.com/api/v1/vc/ata/query

请求方式:HTTP GET

字段
说明
是否必填
备注
appid应用标识用于标识当前应用。
id任务 ID这里填写的是submit接口返回的id。
blocking查询结果时是否阻塞0表示非阻塞,1表示阻塞(默认是阻塞模式)。

请求示例:

GET /api/v1/vc/ata/query?appid=your_appid&id=fc5aa03e-6ae4-46a3-b8cf-1910a44e0d8a HTTP/1.1
Host: openspeech.bytedance.com

4.2 应答

应答格式:JSON

应答字段:

字段
说明
层级
格式
是否必填
备注
id任务 ID1string
code状态码1int0 为成功,非 0 为失败。详情请参考错误码
message状态信息1string
utterances分句结果1list仅当成功时填写。
start_time起始时间2int距离音频开始的毫秒偏移值。
end_time结束时间2int距离音频开始的毫秒偏移值。
text文本2string
words词粒度信息2list

应答示例:

{
    "id": "d22cca84-8c8a-4d15-aa2c-ac550518d5ae",
    "code": 0,
    "message": "Success",
    "duration": 5.3174375,
    "utterances": [
        {
            "text": "如果您没有其他需要举报的话这边就先挂断了",
            "start_time": 0,
            "end_time": 3197,
            "words": [
                {
                    "text": "如",
                    "start_time": 0,
                    "end_time": 208
                },
                {
                    "text": "果",
                    "start_time": 208,
                    "end_time": 317
                },
                {
                    "text": "您",
                    "start_time": 322,
                    "end_time": 460
                },
                {
                    "text": "没",
                    "start_time": 460,
                    "end_time": 580
                },
                {
                    "text": "有",
                    "start_time": 580,
                    "end_time": 717
                },
                {
                    "text": "其",
                    "start_time": 722,
                    "end_time": 877
                },
                {
                    "text": "他",
                    "start_time": 882,
                    "end_time": 1037
                },
                {
                    "text": "需",
                    "start_time": 1042,
                    "end_time": 1180
                },
                {
                    "text": "要",
                    "start_time": 1180,
                    "end_time": 1317
                },
                {
                    "text": "举",
                    "start_time": 1322,
                    "end_time": 1477
                },
                {
                    "text": "报",
                    "start_time": 1482,
                    "end_time": 1637
                },
                {
                    "text": "的",
                    "start_time": 1642,
                    "end_time": 1780
                },
                {
                    "text": "话",
                    "start_time": 1780,
                    "end_time": 1917
                },
                {
                    "text": "这",
                    "start_time": 2042,
                    "end_time": 2180
                },
                {
                    "text": "边",
                    "start_time": 2180,
                    "end_time": 2317
                },
                {
                    "text": "就",
                    "start_time": 2322,
                    "end_time": 2460
                },
                {
                    "text": "先",
                    "start_time": 2460,
                    "end_time": 2597
                },
                {
                    "text": "挂",
                    "start_time": 2602,
                    "end_time": 2757
                },
                {
                    "text": "断",
                    "start_time": 2802,
                    "end_time": 2957
                },
                {
                    "text": "了",
                    "start_time": 3042,
                    "end_time": 3197
                }
            ]
        },
        {
            "text": "祝您生活愉快再见",
            "start_time": 3442,
            "end_time": 4877,
            "words": [
                {
                    "text": "祝",
                    "start_time": 3442,
                    "end_time": 3580
                },
                {
                    "text": "您",
                    "start_time": 3580,
                    "end_time": 3717
                },
                {
                    "text": "生",
                    "start_time": 3722,
                    "end_time": 3877
                },
                {
                    "text": "活",
                    "start_time": 3882,
                    "end_time": 4020
                },
                {
                    "text": "愉",
                    "start_time": 4020,
                    "end_time": 4157
                },
                {
                    "text": "快",
                    "start_time": 4162,
                    "end_time": 4317
                },
                {
                    "text": "再",
                    "start_time": 4562,
                    "end_time": 4717
                },
                {
                    "text": "见",
                    "start_time": 4722,
                    "end_time": 4877
                }
            ]
        }
    ]
}

5. 错误码
类别/状态号
含义
说明
0成功
2000正在处理任务处理中。
请求类
1001请求参数无效请求参数缺失必需字段 / 字段值无效 / 重复请求。
1002无访问权限token 无效 / 过期 / 无权访问指定服务。
1003访问超频当前 appid 访问 QPS 超出设定阈值。
1004访问超额当前 appid 访问次数超出限制。
1005服务器繁忙服务过载,无法处理当前请求。
1008 - 1009保留号段待定。
音频类
1010音频过长音频数据时长超出阈值。
1011音频过大音频数据大小超出阈值。
1012音频格式无效音频 header 有误 / 无法进行音频解码。
1013音频静音音频未识别出任何文本结果。
1014 - 1019保留号段待定。
识别类
1020识别等待超时识别等待过程超时。
1021识别处理超时识别处理过程超时。
1022识别错误识别过程中发生错误。
1023 - 1029保留号段待定。
1099未知错误未归类错误。
7. Demo

以下 demo 均使用 token 鉴权方式。

curl

submit

curl -X POST -H 'Accept: */*' -H 'Authorization: Bearer; ${your_token}' -H 'Connection: keep-alive' -H 'User-Agent: python-requests/2.22.0' -H 'content-type: application/json' -d '{"url": "${your_url}", "audio_text": "${your_audio_text}"}' 'https://openspeech.bytedance.com/api/v1/vc/ata/submit?appid=${your_appid}&caption_type=speech'

query

curl -X GET -H 'Accept: */*' -H 'Authorization: Bearer; ${your_token}' -H 'Connection: keep-alive' -H 'User-Agent: python-requests/2.22.0' 'https://openspeech.bytedance.com/api/v1/vc/ata/query?appid=${your_appid}&id=fbf5edcf-378e-4f54-8a7f-5d8fd5e5e2f1'

Python

  • URL音频版本:
    url_sta_demo.py
    1.35KB
  • 二进制音频版本:
    binary_sta_demo.py
    1.39KB

JAVA

  • URL音频版本:
    url_sta_demo.java
    2.35KB

CPP

  • URL音频版本:
    url_sta_demo.cc
    3.08KB