python - 如何使用 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
解决方案
推荐阅读
- powerbi - 如何在 PowerBI 中对文本过滤器进行模糊匹配
- git - 我正在尝试解决本地功能分支中的 git 冲突,但发生了一些奇怪的事情
- .net - 异步的Kafka生产者不返回DeliveryReport但DeliveryResult
- python - Python while循环为变量返回0
- maven - 替换 Maven 中的版本
- blazor - 在 Blazor 中,为什么调用 NavigationManager.NavigateTo 有时会导致使用旧值进行额外的 OnParametersSetAsync 调用?
- javascript - Javascript可以访问/读取第三方/跨域cookie吗?
- excel - 我将使用什么公式来计算一个单元格中的值,但前提是另一个单元格为空白?
- java - 根据 Java Spring 请求在 React 中设置状态
- python-3.x - 在 Pandas 滚动时使用带有参数的自定义函数