This commit is contained in:
yumoqing 2024-09-13 11:10:41 +08:00
parent 7de2590d0a
commit 5b958b09a1

View File

@ -41,9 +41,7 @@ class AudioTrackVad(MediaStreamTrack):
self.running = False self.running = False
def frame2bytes(self, frame): def frame2bytes(self, frame):
# 假设你有一个 AudioFrame 对象 audio_frame
audio_array = frame.to_ndarray() audio_array = frame.to_ndarray()
# 将 numpy 数组转换为字节数组
dtype = audio_array.dtype dtype = audio_array.dtype
audio_bytes = audio_array.tobytes() audio_bytes = audio_array.tobytes()
return audio_bytes return audio_bytes
@ -52,7 +50,7 @@ class AudioTrackVad(MediaStreamTrack):
oldf = await self.track.recv() oldf = await self.track.recv()
self.sample_rate = oldf.sample_rate self.sample_rate = oldf.sample_rate
duration = (oldf.samples * 1000) / oldf.sample_rate duration = (oldf.samples * 1000) / oldf.sample_rate
print(f'{duration=}, {oldf.samples=}, (oldf.sample_rate=}') print(f'{self.__class__.__name__}.recv(): {duration=}, {oldf.samples=}, (oldf.sample_rate=}')
frames = self.resample(oldf) frames = self.resample(oldf)
for f in frames: for f in frames:
if self.debug: if self.debug: