添加语音websocket等,还没测试
This commit is contained in:
63
keyBoard/Class/AiTalk/VM/AudioStreamPlayer.h
Normal file
63
keyBoard/Class/AiTalk/VM/AudioStreamPlayer.h
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// AudioStreamPlayer.h
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2026/1/15.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/// 流式音频播放器代理
|
||||
@protocol AudioStreamPlayerDelegate <NSObject>
|
||||
@optional
|
||||
/// 开始播放片段
|
||||
- (void)audioStreamPlayerDidStartSegment:(NSString *)segmentId;
|
||||
/// 播放时间更新
|
||||
- (void)audioStreamPlayerDidUpdateTime:(NSTimeInterval)time
|
||||
segmentId:(NSString *)segmentId;
|
||||
/// 片段播放完成
|
||||
- (void)audioStreamPlayerDidFinishSegment:(NSString *)segmentId;
|
||||
@end
|
||||
|
||||
/// PCM 流式播放器
|
||||
/// 使用 AVAudioEngine + AVAudioPlayerNode 实现低延迟播放
|
||||
@interface AudioStreamPlayer : NSObject
|
||||
|
||||
@property(nonatomic, weak) id<AudioStreamPlayerDelegate> delegate;
|
||||
|
||||
/// 是否正在播放
|
||||
@property(nonatomic, assign, readonly, getter=isPlaying) BOOL playing;
|
||||
|
||||
/// 启动播放器
|
||||
/// @param error 错误信息
|
||||
/// @return 是否启动成功
|
||||
- (BOOL)start:(NSError **)error;
|
||||
|
||||
/// 停止播放器
|
||||
- (void)stop;
|
||||
|
||||
/// 入队 PCM 数据块
|
||||
/// @param pcmData PCM Int16 数据
|
||||
/// @param sampleRate 采样率
|
||||
/// @param channels 通道数
|
||||
/// @param segmentId 片段 ID
|
||||
- (void)enqueuePCMChunk:(NSData *)pcmData
|
||||
sampleRate:(double)sampleRate
|
||||
channels:(int)channels
|
||||
segmentId:(NSString *)segmentId;
|
||||
|
||||
/// 获取片段的当前播放时间
|
||||
/// @param segmentId 片段 ID
|
||||
/// @return 当前时间(秒)
|
||||
- (NSTimeInterval)playbackTimeForSegment:(NSString *)segmentId;
|
||||
|
||||
/// 获取片段的总时长
|
||||
/// @param segmentId 片段 ID
|
||||
/// @return 总时长(秒)
|
||||
- (NSTimeInterval)durationForSegment:(NSString *)segmentId;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Reference in New Issue
Block a user