Search code examples
rubygoogle-cloud-platformruby-on-rails-5speech-to-textgoogle-speech-api

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


Working on a WebAppon Ruby on Rails. I want to get subtitle for Pre recorded video and also for new videos going to record.

I have implemented the gem 'google-cloud-speech'.

But now I'm not able to get text for my video. I get a suggestion from Google Cloud API doc to add model but when I add model: 'video' to configuration, it says there is no such field model in initialization map entry.

My code without adding model is as per below.

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

which is giving me error message like below.

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'

Any help is appreciated.

Thanks


Solution

  • Regarding the model issue, this might be due to that the video model is not available yet for Ruby V1 API version as this feature it's part of the v1p1beta1 version.

    Regarding your code issue, I just did the example shown here successfully. It would be helpful if you attach your full code as the documented code works well.