使用websocket请求asr服务
初始化的时候,建立了一个Timer,定时向服务端发送ping消息,防止服务端10秒判断没有消息主动关闭连接,
然后第一次请求成功,并获取到asr结果,客户端没有关闭
第二次请求的时候 发送StartTranscription消息,消息的json格式确定正确
{"header":{"message_id":"6762c27a2d9c7c4aee79cd28f12af38c","task_id":"a2ed7323a09cbed9c3b260dc01f07353","namespace":"SpeechTranscriber","name":"StartTranscription","appkey":"7cawGVexLmMra6KL"},"payload":{"format":"PCM","sample_rate":16000,"enable_intermediate_result":true,"enable_punctuation_prediction":true,"enable_inverse_text_normalization":true}}
taskid和第一次一样(taskid不一样时候现象一样)然后触发了onMessage和onDisconnection回调
分别收到
{"header":{"namespace":"Default","name":"TaskFailed","status":40000002,"message_id":"b164481cf2ff41e397595e72cdf48c90","task_id":"a2ed7323a09cbed9c3b260dc01f07353","status_text":"Gateway:MESSAGE_INVALID:Invalid binary message while server state is 'ROUTING'"}}1234567。","confidence":0.877,"words":[],"status":0,"gender":"","begin_time":1870,"fixed_result":"","unfixed_result":"","stash_result":{"sentenceId":2,"beginTime":3860,"text":"","fixedText":"","unfixedText":"","currentTime":3860,"words":[]},"audio_extra_info":"","sentence_id":"83d80823719a4b05aa9fdd996cb9faeb","gender_score":0.0}}
以及
40000002":{"namespace":"Default","name":"TaskFailed","status":40000002,"message_id":"b164481cf2ff41e397595e72cdf48c90","task_id":"a2ed7323a09cbed9c3b260dc01f07353","status_text":"Gateway:MESSAGE_INVALID:Invalid binary message while server state is 'ROUTING'"}}1234567。","confidence":0.877,"words":[],"status":0,"gender":"","begin_time":1870,"fixed_result":"","unfixed_result":"","stash_result":{"sentenceId":2,"beginTime":3860,"text":"","fixedText":"","unfixedText":"","currentTime":3860,"words":[]},"audio_extra_info":"","sentence_id":"83d80823719a4b05aa9fdd996cb9faeb","gender_score":0.0}}
检查消息格式:
确保发送的消息格式符合服务器的要求。检查 JSON 对象是否完整且格式正确。
检查编码问题:
如果消息中包含特殊字符,确保它们被正确编码。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
人工智能平台 PAI(Platform for AI,原机器学习平台PAI)是面向开发者和企业的机器学习/深度学习工程平台,提供包含数据标注、模型构建、模型训练、模型部署、推理优化在内的AI开发全链路服务,内置140+种优化算法,具备丰富的行业场景插件,为用户提供低门槛、高性能的云原生AI工程化能力。