首页 > 解决方案 > 如何使用 WebRTC 在 Python 中将音频从麦克风流式传输到 Google Speech-to-Text

问题描述

我正在寻找有关使用 Google Cloud Speach-To-Text 转录来自 WebRTC 的音频流数据的文档。我在 Python 中使用aiortc作为库来处理来自客户端 Web 应用程序的视频和音频流。

这是我用来处理音频数据的类的片段。

class AudioTransformTrack(MediaStreamTrack):
        kind = "audio"
    
        def __init__(self, track):
            super().__init__()
            self.track = track
    
        async def recv(self):
            frame = await self.track.recv()
            data_np = frame.to_ndarray().astype(dtype='float32').reshape(1920, )
            # print("data_np.shape:", data_np.shape)
            y_16k = librosa.resample(data_np, 48000, 16000)
            audio_data = y_16k.astype(dtype='int16').tobytes()
            return frame

标签: pythonwebrtcgoogle-speech-apiaiortc

解决方案


推荐阅读