Replies: 1 comment
-
我试了,想用队列输出声音不行 class diyKindAudio(MediaStreamTrack):
kind = "audio"
def __init__(self):
super().__init__() #必须初始化 VideoStreamTrack
self.cap = audio_queue #cv2.VideoCapture(0, cv2.CAP_DSHOW) #本地摄像头
async def recv(self):
audio_frame = audio_queue.get(timeout=1) # 从音频队列中取样本
print(f"------音频帧 Audio data shape: {audio_frame.shape}")
if not audio_frame:
raise Exception("--音频队列为空--")
# 2、推流声音
frame = audio_frame.astype(np.int16)
new_frame = AudioFrame(format='s16', layout='mono', samples=frame.shape[0]) # 创建一个单声道,采样率为44100Hz的AudioFrame
new_frame.planes[0].update(frame.tobytes()) # __video_frame_buffer=frame.tobytes()
new_frame.sample_rate=24000 #原来:16000
return new_frame |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How to implement
AudioTransformTrack
likeVideoTransformTrack
in https://github.com/aiortc/aiortc/blob/main/examples/server/server.py#L22You should add
and replace https://github.com/aiortc/aiortc/blob/main/examples/server/server.py#L141 with
The following code is NG except uncomment
# return frame #! OK
Beta Was this translation helpful? Give feedback.
All reactions