json文本
{ "status": 0, "result": { "final": true, "hypotheses": [{ "likelihood": 333.86676025390625, "transcript": "温格你家,", "word-alignment": [{ "word": "温", "start": 3.4799999222159386, "length": 0.20999999530613422 }, { "word": "格", "start": 3.689999917522073, "length": 0.29999999329447746 }, { "word": "你家", "start": 4.229999905452132, "length": 0.3899999912828207 }] }] }, "segment-start": 0, "segment-length": 5.6099998746067286, "total-length": 5.9658750000000005, "segment": 0, "id": "d5e52f52-3d18-4f3e-9379-902183f3ac25" } { "status": 0, "result": { "final": true, "hypotheses": [{ "likelihood": 179.34283447265625, "transcript": "温格你家小朋友今年上。", "word-alignment": [{ "word": "温", "start": 0.6899999845772982, "length": 0.20999999530613422 }, { "word": "格", "start": 0.8999999798834324, "length": 0.2699999939650297 }, { "word": "你家", "start": 1.4399999678134918, "length": 0.3899999912828207 }, { "word": "小朋友", "start": 1.8299999590963125, "length": 0.6299999859184027 }, { "word": "今年", "start": 2.5199999436736107, "length": 0.41999999061226845 }, { "word": "上", "start": 2.969999933615327, "length": 0.47999998927116394 }] }] }, "segment-start": 5.9658750000000005, "segment-length": 4.0799999088048935, "total-length": 10.215875, "segment": 1, "id": "d5e52f52-3d18-4f3e-9379-902183f3ac25" }
解析方法:
import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; ObjectMapper objectMapper = new ObjectMapper(); try { ASRRecognizedResponse response = objectMapper.readValue(json, ASRRecognizedResponse.class); System.out.println(response); } catch (IOException e) { e.printStackTrace(); }
相关实体类
import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class ASRRecognizedResponse { private String status; private String message; private Result result; @JsonProperty("segment-start") private String segmentStart; @JsonProperty("segment-length") private Float segmentLength; @JsonProperty("total-length") private Float totalLength; private short segment; private String id; }
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @JsonIgnoreProperties("word-alignment") public class Hypotheses { private Float likelihood; private String transcript; }
import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import lombok.NoArgsConstructor; import java.util.List; @Data @NoArgsConstructor public class Result{ @JsonProperty("final") private Boolean finished; private List<Hypotheses> hypotheses; }
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。