使用 Rails 应用程序通过 google 云语音将视频转换为文本(文字记录)

Convert Video to text(transcript) by google cloud speech to text with Rails Application

在 Rails 上 Ruby 开发 WebApp。 我想为预录视频和即将录制的新视频获取字幕。

我已经实现了gem 'google-cloud-speech'

但现在我无法为我的视频获取文字。我从 Google Cloud API 文档中得到了添加模型的建议,但是当我将 model: 'video' 添加到配置时,它说初始化映射条目中没有这样的字段 model

我没有添加模型的代码如下。

speech_client = Google::Cloud::Speech.new
config ={ encoding: :LINEAR16,
          sample_rate_hertz: 16000,
          language_code: "en-US",
        }
audio = { uri: @uri }
response = speech.recognize config, audio

给我如下错误信息。

Google::Gax::RetryError: GaxError Exception occurred in retry method that was not classified as transient, caused by 3:Request contains an invalid argument. from /Users/hiren/.rvm/gems/ruby-2.5.1@Snip/gems/google-gax-1.3.0/lib/google/gax/api_callable.rb:369:in `rescue in block in retryable'

感谢任何帮助。

谢谢

关于模型问题,这可能是由于 video model 尚不适用于 Ruby V1 API 版本,因为此功能是v1p1beta1版本。

关于您的代码问题,我只是成功地完成了显示的示例 here。如果您附上完整的代码将会很有帮助,因为文档中的代码运行良好。