52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
|
|
//
|
|||
|
|
// ASRStreamClient.h
|
|||
|
|
// keyBoard
|
|||
|
|
//
|
|||
|
|
// Created by Mac on 2026/1/15.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#import <Foundation/Foundation.h>
|
|||
|
|
|
|||
|
|
NS_ASSUME_NONNULL_BEGIN
|
|||
|
|
|
|||
|
|
/// ASR 流式识别客户端代理
|
|||
|
|
@protocol ASRStreamClientDelegate <NSObject>
|
|||
|
|
@required
|
|||
|
|
/// 收到实时识别结果(部分文本)
|
|||
|
|
- (void)asrClientDidReceivePartialText:(NSString *)text;
|
|||
|
|
/// 收到最终识别结果
|
|||
|
|
- (void)asrClientDidReceiveFinalText:(NSString *)text;
|
|||
|
|
/// 识别失败
|
|||
|
|
- (void)asrClientDidFail:(NSError *)error;
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
/// ASR 流式识别客户端
|
|||
|
|
/// 使用 NSURLSessionWebSocketTask 实现流式语音识别
|
|||
|
|
@interface ASRStreamClient : NSObject
|
|||
|
|
|
|||
|
|
@property(nonatomic, weak) id<ASRStreamClientDelegate> delegate;
|
|||
|
|
|
|||
|
|
/// ASR 服务器 WebSocket URL
|
|||
|
|
@property(nonatomic, copy) NSString *serverURL;
|
|||
|
|
|
|||
|
|
/// 是否已连接
|
|||
|
|
@property(nonatomic, assign, readonly, getter=isConnected) BOOL connected;
|
|||
|
|
|
|||
|
|
/// 开始新的识别会话
|
|||
|
|
/// @param sessionId 会话 ID
|
|||
|
|
- (void)startWithSessionId:(NSString *)sessionId;
|
|||
|
|
|
|||
|
|
/// 发送 PCM 音频帧(20ms / 640 bytes)
|
|||
|
|
/// @param pcmFrame PCM 数据
|
|||
|
|
- (void)sendAudioPCMFrame:(NSData *)pcmFrame;
|
|||
|
|
|
|||
|
|
/// 结束当前会话,请求最终结果
|
|||
|
|
- (void)finalize;
|
|||
|
|
|
|||
|
|
/// 取消会话
|
|||
|
|
- (void)cancel;
|
|||
|
|
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
NS_ASSUME_NONNULL_END
|