bugfix
This commit is contained in:
parent
5a6d421b3d
commit
ec070ff771
@ -6,6 +6,23 @@ from av import AudioFrame
|
|||||||
|
|
||||||
from aiortc import VideoStreamTrack, AudioStreamTrack
|
from aiortc import VideoStreamTrack, AudioStreamTrack
|
||||||
|
|
||||||
|
def bytes_to_audio_frame(bytes_data, format='s16', layout='mono', sample_rate=16000):
|
||||||
|
"""
|
||||||
|
从字节数据构造av.AudioFrame对象。
|
||||||
|
|
||||||
|
参数:
|
||||||
|
- bytes_data: 字节数据,代表音频内容。
|
||||||
|
- format: 音频样本格式字符串,如's16'表示16位有符号整数。
|
||||||
|
- layout: 通道布局,如'mono'、'stereo'等。
|
||||||
|
- sample_rate: 采样率。
|
||||||
|
"""
|
||||||
|
# 根据给定的参数创建AudioFrame
|
||||||
|
frame = av.AudioFrame(format=format, layout=layout, samples=len(bytes_data) // av.AudioFrame.format_size(format), rate=sample_rate)
|
||||||
|
|
||||||
|
# 将字节数据复制到AudioFrame中
|
||||||
|
frame.planes[0].update(bytes_data)
|
||||||
|
return frame
|
||||||
|
|
||||||
class LLMAudioStreamTrack(AudioStreamTrack):
|
class LLMAudioStreamTrack(AudioStreamTrack):
|
||||||
def __init__(self, omni_infer):
|
def __init__(self, omni_infer):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -19,7 +36,7 @@ class LLMAudioStreamTrack(AudioStreamTrack):
|
|||||||
b = self.get_audio_bytes()
|
b = self.get_audio_bytes()
|
||||||
if b is None:
|
if b is None:
|
||||||
return await super().recv()
|
return await super().recv()
|
||||||
frame = AudioFrame.from_ndarray(io.BytesIO(b), format='s16', layout='mono')
|
frame = bytes_to_audio_frame(b)
|
||||||
print('LLMAudioStreamTrack return frame ...')
|
print('LLMAudioStreamTrack return frame ...')
|
||||||
return frame
|
return frame
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user