c++ - 在 C++ 中将 Gstreamer 与 Google 语音 API(流式转录)结合使用

标签 c++ speech-recognition gstreamer grpc google-speech-api

我正在使用来自云平台的 Google Speech API 获取流式音频的语音到文本。我已经使用 GCP 使用 curl POST 请求对 short audio file 完成了 REST API 调用。

我看到了 documentation的 Google Streaming Recognize,上面写着“只能通过 gRPC 进行流式语音识别。”

我在我的 OpenSuse Leap 15.0 中安装了 gRPC(也是 protobuf)。这是目录的屏幕截图。

Directory

接下来我尝试运行来自 this link 的 streaming_transcribe 示例, 我发现示例程序使用本地文件作为输入,但将其模拟为麦克风输入(顺序捕获 64K block ),然后将数据发送到 Google 服务器。

为了检查 grpc 在我的系统上是否正确设置的初始测试,我运行了 make run_tests。我已将 Makefile 更改为:

...
...Some text as original Makefile
...
.PHONY: all
all: streaming_transcribe
googleapis.ar: $(GOOGLEAPIS_CCS:.cc=.o) 
      ar r $@ $?
streaming_transcribe: streaming_transcribe.o parse_arguments.o googleapis.ar
      $(CXX) $^ $(LDFLAGS) -o $@
run_tests:
      ./streaming_transcribe -b 16000 resources/audio.raw
      ./streaming_transcribe --bitrate 16000 resources/audio2.raw
      ./streaming_transcribe resources/audio.flac
      ./streaming_transcribe resources/quit.raw
clean: rm -f *.o streaming_transcribe \
       googleapis.ar \
       $(GOOGLEAPIS_CCS:.cc=.o)

工作得很好(原来的 Makefile 也没有)。 但是 streaming_transcribe.o 文件是在运行 Makefile 之后创建的。所以我手动运行文件并得到以下响应

Screenshot2

关于如何运行测试和使用 gstreamer 而不是用于模拟麦克风音频的函数有什么建议吗?

最佳答案

how to run the test

按照 cpp-docs-samples 上的说明进行操作. 先决条件 - 安装 grpc , protobuf , 和 googleapis并按照上面的链接设置环境。

gstreamer instead of the function used for simulating the mic-phone audio

对于这个程序,我创建了管道

gst-launch-1.0 filesrc location=/path/to/file/FOO.wav ! wavparse ! audioconvert ! audio/x-raw,channels=1,depth=16,width=16,rate=44100 ! rtpL16pay  ! udpsink host=xxx.xxx.xxx.xxx port=yyyy

通过在管道中更改适当的 elemnet,可以将音频文件更改为 flac 或 mp3

gst-launch-1.0 udpsrc port=yyyy ! "application/x-rtp,media=(string)audio, clock-rate=(int)44100, width=16, height=16, encoding-name=(string)L16, encoding-params=(string)1, channels=(int)1, channel-positions=(int)1, payload=(int)96" ! rtpL16depay ! audioconvert ! audio/x-raw,format=S16LE ! filesink location=/path/to/where/you/want/to/dump/the/rtp/payloads/ABC.raw

从 rtp 流中获取有效负载并将其写入文件的过程是在另一个线程中完成的,而不是将数据发送到 google 并读取响应。

关于c++ - 在 C++ 中将 Gstreamer 与 Google 语音 API(流式转录)结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54514814/

相关文章:

c++ - 如何在 C++ 中获取进程名称

c++ - 为什么基于范围的 for 语句通过 auto&& 获取范围?

speech-recognition - 语音识别与编程

html - 使用 Webkit speech api 进行连续语音识别

speech-recognition - 当一个人说话时识别片段?

c++ - 错误/usr/include/string.h :652:42: error: ‘memcpy’ was not declared in this scope while building caffe

c# - 在 C# 中调用 C++ 导出的函数

c++ - Gstreamer 的 OpenCV 3.0.0 错误

ffmpeg - 从网络摄像头编码未压缩的 avi

video-streaming - 使用GStreamer播放传入的RTP流