161 lines
3.7 KiB
Java
161 lines
3.7 KiB
Java
package com.rj.dto;
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import lombok.Data;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 语音转文本响应DTO
|
|
*
|
|
* @author rj
|
|
* @date 2025-01-02
|
|
*/
|
|
@Data
|
|
@Schema(description = "语音转文本响应结果")
|
|
public class AsrResponse {
|
|
|
|
/**
|
|
* 是否成功
|
|
*/
|
|
@Schema(description = "是否成功")
|
|
private boolean success;
|
|
|
|
/**
|
|
* 消息
|
|
*/
|
|
@Schema(description = "响应消息")
|
|
private String message;
|
|
|
|
/**
|
|
* 识别结果文本
|
|
*/
|
|
@Schema(description = "识别结果文本")
|
|
private String text;
|
|
|
|
/**
|
|
* 识别结果列表(包含时间戳和说话人信息)
|
|
*/
|
|
@Schema(description = "识别结果列表")
|
|
private List<AsrResult> results;
|
|
|
|
/**
|
|
* 音频时长(秒)
|
|
*/
|
|
@Schema(description = "音频时长(秒)")
|
|
private Double duration;
|
|
|
|
/**
|
|
* 处理时间(毫秒)
|
|
*/
|
|
@Schema(description = "处理时间(毫秒)")
|
|
private Long processingTimeMs;
|
|
|
|
/**
|
|
* 任务ID
|
|
*/
|
|
@Schema(description = "任务ID")
|
|
private String taskId;
|
|
|
|
/**
|
|
* 请求ID
|
|
*/
|
|
@Schema(description = "请求ID")
|
|
private String requestId;
|
|
|
|
/**
|
|
* 错误代码
|
|
*/
|
|
@Schema(description = "错误代码")
|
|
private String errorCode;
|
|
|
|
/**
|
|
* 错误信息
|
|
*/
|
|
@Schema(description = "错误信息")
|
|
private String errorMessage;
|
|
|
|
/**
|
|
* 创建时间
|
|
*/
|
|
@Schema(description = "创建时间")
|
|
private LocalDateTime createTime;
|
|
|
|
/**
|
|
* 识别结果详情
|
|
*/
|
|
@Data
|
|
@Schema(description = "识别结果详情")
|
|
public static class AsrResult {
|
|
|
|
/**
|
|
* 开始时间(秒)
|
|
*/
|
|
@Schema(description = "开始时间(秒)")
|
|
private Double startTime;
|
|
|
|
/**
|
|
* 结束时间(秒)
|
|
*/
|
|
@Schema(description = "结束时间(秒)")
|
|
private Double endTime;
|
|
|
|
/**
|
|
* 识别文本
|
|
*/
|
|
@Schema(description = "识别文本")
|
|
private String text;
|
|
|
|
/**
|
|
* 说话人ID
|
|
*/
|
|
@Schema(description = "说话人ID")
|
|
private String speakerId;
|
|
|
|
/**
|
|
* 置信度
|
|
*/
|
|
@Schema(description = "置信度")
|
|
private Double confidence;
|
|
}
|
|
|
|
/**
|
|
* 创建成功响应
|
|
*/
|
|
public static AsrResponse success(String text, List<AsrResult> results, Double duration,
|
|
Long processingTimeMs, String taskId, String requestId) {
|
|
AsrResponse response = new AsrResponse();
|
|
response.setSuccess(true);
|
|
response.setMessage("语音识别成功");
|
|
response.setText(text);
|
|
response.setResults(results);
|
|
response.setDuration(duration);
|
|
response.setProcessingTimeMs(processingTimeMs);
|
|
response.setTaskId(taskId);
|
|
response.setRequestId(requestId);
|
|
response.setCreateTime(LocalDateTime.now());
|
|
return response;
|
|
}
|
|
|
|
/**
|
|
* 创建错误响应
|
|
*/
|
|
public static AsrResponse error(String message) {
|
|
return error(message, null, null);
|
|
}
|
|
|
|
/**
|
|
* 创建错误响应
|
|
*/
|
|
public static AsrResponse error(String message, String errorCode, String errorMessage) {
|
|
AsrResponse response = new AsrResponse();
|
|
response.setSuccess(false);
|
|
response.setMessage(message);
|
|
response.setErrorCode(errorCode);
|
|
response.setErrorMessage(errorMessage);
|
|
response.setCreateTime(LocalDateTime.now());
|
|
return response;
|
|
}
|
|
}
|