This topic describes how to query the status and results of real-time recording tasks.
You can query the processing results using the TaskId that is returned after you submit the task.
If you use this method to poll for results, do not set the polling frequency too high to avoid rate limiting. For example, you can query at a frequency of every 1 minute or every 5 minutes.
Using callback notifications to retrieve results is different from active polling. After you submit a task, the server-side can proactively notify you of the task status when processing is complete.
You can be notified of the task processing status through HTTP callbacks.
Query task status and results
When you query a task, use the TaskId that was returned from the task submission step as input. Initiate a query request and check the returned status to determine whether the task is complete.
Request parameters
Parameter | Type | Required | Description |
TaskId | string | Yes | The TaskId returned when you submitted the task. |
Sample code
#!/usr/bin/env python
#coding=utf-8
import os
import json
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
from aliyunsdkcore.auth.credentials import AccessKeyCredential
def create_common_request(domain, version, protocolType, method, uri):
request = CommonRequest()
request.set_accept_format('json')
request.set_domain(domain)
request.set_version(version)
request.set_protocol_type(protocolType)
request.set_method(method)
request.set_uri_pattern(uri)
request.add_header('Content-Type', 'application/json')
return request
# TODO: Set your AccessKeyId and AccessKeySecret using environment variables.
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
client = AcsClient(region_id='cn-beijing', credential=credentials)
uri = '/openapi/tingwu/v2/tasks' + '/' + 'Enter the TaskId returned when you submitted the task'
request = create_common_request('tingwu.cn-beijing.aliyuncs.com', '2023-09-30', 'https', 'GET', uri)
response = client.do_action_with_exception(request)
print("response: \n" + json.dumps(json.loads(response), indent=4, ensure_ascii=False))package com.alibaba.tingwu.client.demo.common;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import org.junit.Test;
/**
* @author tingwu2023
* @desc This demo shows how to call the OpenAPI to query the task status and results by TaskId.
*/
public class GetTaskInfoTest {
@Test
public void getTaskInfo() throws ClientException {
String taskId = "Enter the TaskId for the created task (including offline transcription and real-time meetings)";
String queryUrl = String.format("/openapi/tingwu/v2/tasks" + "/%s", taskId);
CommonRequest request = createCommonRequest("tingwu.cn-beijing.aliyuncs.com", "2023-09-30", ProtocolType.HTTPS, MethodType.GET, queryUrl);
// TODO: Set your AccessKeyId and AccessKeySecret using environment variables.
DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
}
public static CommonRequest createCommonRequest(String domain, String version, ProtocolType protocolType, MethodType method, String uri) {
// Create an API request and set its parameters.
CommonRequest request = new CommonRequest();
request.setSysDomain(domain);
request.setSysVersion(version);
request.setSysProtocol(protocolType);
request.setSysMethod(method);
request.setSysUriPattern(uri);
request.setHttpContentType(FormatType.JSON);
return request;
}
}package main
import (
"encoding/json"
"log"
"os"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)
type GetTaskInfoResponse struct {
RequestId string `json:"RequestId"`
Code string `json:"Code"`
Message string `json:"Message"`
Data struct {
TaskId string `json:"TaskId"`
TaskKey string `json:"TaskKey"`
TaskStatus string `json:"TaskStatus"`
} `json:"Data"`
}
func get_task_info(taskid string, akkey string, aksecret string) (*GetTaskInfoResponse, string, error) {
client, err := sdk.NewClientWithAccessKey("cn-beijing", akkey, aksecret)
if err != nil {
return nil, "", err
}
request := requests.NewCommonRequest()
request.Method = "GET"
request.Domain = "tingwu.cn-beijing.aliyuncs.com"
request.Version = "2023-09-30"
request.PathPattern = "/openapi/tingwu/v2/tasks/" + taskid
request.SetScheme("https")
log.Default().Print("request task:", taskid)
response, err := client.ProcessCommonRequest(request)
if err != nil {
return nil, "", err
}
log.Default().Print("response body:\n", string(response.GetHttpContentBytes()))
resp := new(GetTaskInfoResponse)
err = json.Unmarshal(response.GetHttpContentBytes(), resp)
if err != nil {
return nil, response.GetHttpContentString(), err
}
return resp, response.GetHttpContentString(), nil
}
func main() {
akkey := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
aksecret := os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
_, raw, _ := get_task_info("Enter the TaskId for the created task (including offline transcription and real-time meetings)", akkey, aksecret)
log.Default().Println("response :", raw)
}#include <cstdlib>
#include <iostream>
#include <string>
#include <alibabacloud/core/AlibabaCloud.h>
#include <alibabacloud/core/CommonRequest.h>
#include <alibabacloud/core/CommonClient.h>
#include <alibabacloud/core/CommonResponse.h>
/**
* @author tingwu2023
* @desc This demo shows how to call the OpenAPI to query the task status and results by TaskId.
*/
int main( int argc, char** argv ) {
std::string taskId = "Enter the TaskId for the created task (including offline transcription and real-time recording)";
AlibabaCloud::InitializeSdk();
AlibabaCloud::ClientConfiguration configuration( "cn-beijing" );
// specify timeout when create client.
configuration.setConnectTimeout(1500);
configuration.setReadTimeout(4000);
// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
AlibabaCloud::Credentials credential( getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") );
AlibabaCloud::CommonClient client( credential, configuration );
AlibabaCloud::CommonRequest request(AlibabaCloud::CommonRequest::RequestPattern::RoaPattern);
request.setHttpMethod(AlibabaCloud::HttpRequest::Method::Get);
request.setDomain("tingwu.cn-beijing.aliyuncs.com");
request.setVersion("2023-09-30");
request.setHeaderParameter("Content-Type", "application/json");
request.setResourcePath("/openapi/tingwu/v2/tasks/" + taskId);
auto response = client.commonResponse(request);
if (response.isSuccess()) {
printf("request success.\n");
printf("result: %s\n", response.result().payload().c_str());
} else {
printf("error: %s\n", response.error().errorMessage().c_str());
printf("request id: %s\n", response.error().requestId().c_str());
}
AlibabaCloud::ShutdownSdk();
return 0;
} Sample outputs
When the task is running:
{
"Code":"0",
"Data":{
"TaskId":"e8adc0b3bc4b42d898fcadb0********",
"TaskStatus":"ONGOING"
},
"Message":"success",
"RequestId":"5fa32fc6-441f-4dd1-bb86-c030********"
}When the task is running and partial results are available:
{
"Code":"0",
"Data":{
"TaskId":"e8adc0b3bc4b42d898fcadb0********",
"TaskStatus":"ONGOING",
"OutputMp3Path":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_20231101141801.mp3?ExLTAI****************AccessKeyId=LTAI****************&Signature=********JBMijH7wLq0xX6aivHc%3D",
"Result":{
"Transcription":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu_data/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_Transcription_20231101141926.json?Expires=1698906034&OSSAcceLTAI****************&Signature=********NJlqSEWJxfkMwjwsHCA%3D"
}
},
"Message":"success",
"RequestId":"1b20e0d9-c55c-4cc3-85af-80b4********"
}When the task is complete:
{
"Code":"0",
"Data":{
"TaskId":"e8adc0b3bc4b42d898fcadb0********",
"TaskStatus":"COMPLETED",
"OutputMp3Path":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_20231101141801.mp3?ExLTAI4G4uXHLPwQHj6oX8****AccessKeyId=LTAI****************&Signature=********JBMijH7wLq0xX6aivHc%3D",
"Result":{
"AutoChapters":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu_data/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_AutoChapters_20231101141955.json?Expires=1698906034&OSSAcceLTAI****************&Signature=********Ax9FvifYAO8dj4qzWg%3D",
"Transcription":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu_data/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_Transcription_20231101141926.json?Expires=1698906034&OSSAccessKeyId=LTAI****************&Signature=********NJlqSEWJxfkMwjwsHCA%3D"
}
},
"Message":"success",
"RequestId":"1b20e0d9-c55c-4cc3-85af-80b4********"
}If the task fails:
{
"Code":"0",
"Data":{
"TaskId":"b76389677b1441fa82165cb1********",
"TaskStatus":"FAILED",
"ErrorCode":"TSC.AudioFileLink",
"ErrorMessage":"Audio file link invalid."
},
"Message":"success",
"RequestId":"d181d898-b627-4040-b7c9-9563********"
}Use callback notifications for task status and results
If you want to use callbacks to retrieve the task status and results, configure the callback type and address in the console. When you create a real-time recording task, set the AppKey parameter to the corresponding project AppKey and set the Input.ProgressiveCallbacksEnabled parameter to true.
When you select the HTTP callback method, a request timeout is enforced. If the system does not receive a response from your server within 5 seconds of sending the request, it stops waiting. The callback request is then considered to have failed, and the system will retry it later.
We recommend that you review and adjust your system to ensure it can respond to callback requests within 5 seconds. This may include, but is not limited to, the following:
Optimize your processing logic for efficient execution.
Process unnecessarily long operations asynchronously instead of waiting for them in the main callback response path.
Implement error handling and retry mechanisms to handle timeouts or failures.
Callback retry mechanism:
If a callback message fails to send, the Tingwu server-side resends the message after 5 seconds. If the second attempt also fails, it resends the message every 5 minutes thereafter, for a maximum of 3 retries.
Sample output
When a single AI model sub-task is complete:
{
"Code":"0",
"Data":{
"TaskId":"e8adc0b3bc4b42d898fcadb0********",
"TaskStatus":"ONGOING",
"TaskKey":"TingwuDemo",
"Result":{
"Transcription":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu_data/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_Transcription_20231101141926.json?Expires=1698906034&OSSAcceLTAI****************&Signature=********NJlqSEWJxfkMwjwsHCA%3D"
}
},
"Message":"success",
"RequestId":"5cf2b587ac6e41e6a1f06ca1********"
}When the task completes:
{
"Code":"0",
"Data":{
"TaskId":"e8adc0b3bc4b42d898fcadb0********",
"TaskStatus":"COMPLETED",
"TaskKey":"TingwuDemo",
"Result":{
"AutoChapters":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu_data/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_AutoChapters_20231101141955.json?Expires=1698906034&OSSAcceLTAI****************&Signature=********Ax9FvifYAO8dj4qzWg%3D",
"Transcription":"http://speech-swap.oss-cn-zhangjiakou.aliyuncs.com/tingwu_data/output/1738248129743478/e8adc0b3bc4b42d898fcadb0a1710635/e8adc0b3bc4b42d898fcadb0a1710635_Transcription_20231101141926.json?Expires=1698906034&OSSAccessKeyId=LTAI****************&Signature=********NJlqSEWJxfkMwjwsHCA%3D"
}
},
"Message":"success",
"RequestId":"9c60b07f152445349eaa6161********"
}If the task fails:
{
"Code":"0",
"Data":{
"TaskId":"e8adc0b3bc4b42d898fcadb0********",
"TaskStatus":"FAILED",
"TaskKey":"TingwuDemo",
"ErrorCode":"TSC.AudioFileLink",
"ErrorMessage":"Audio file link invalid."
},
"Message":"success",
"RequestId":"5e1c0babe36844e49f1b7bee********"
}