googleapis / googleapis/google-cloud-ruby

No error exposed durring :Google:‌:Cloud::Speech.speech#streaming_recognize

Open
#19,236 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
1.4k
Forks
578
Avg merge
1d 11h
Merged PRs (30d)
166

Description

I am trying to stream audio from Twilio using([ twiml](https://www.twilio.com/docs/voice/twiml/stream)) and then transcribe it with google speech to text. Audio streaming is working and I am sending samples to google but I always have this error:
```
google.cloud.speech.v1.Speech.StreamingRecognize
```
This error is only present on the cloud console and I do not have any response from the gem. So, I don't receive transcriptions and no error. Maybe, there is a way to catch an error in gem but I wasn't able to find it.

Screenshot 2022-09-07 at 08 47 08

Code:
```ruby
module Twilio
class CallsController < ApplicationController
include Tubesock::Hijack

def stream
puts "params = #{params.inspect}"

speech = ::Google:‌:Cloud::Speech.speech version: :v1p1beta1 do |config|
config.credentials = Settings.google.credentials_path
end

@input_stream = Gapic::StreamInput.new
speech.streaming_recognize @input_stream do |response, opp|
pp 'transcription'
pp response
pp opp
end
@input_stream.push streaming_config: {
config: {
encoding: 'MULAW',
sample_rate_hertz: 8000,
language_code: "en-US"
}
}

hijack do |tubesock|
tubesock.onopen do
p 'open -s'
end

tubesock.onmessage do |data|
parsed_data = JSON.parse(data)

if parsed_data['event'] == 'connected'
p 'connected'
elsif parsed_data['event'] == 'media'
payload = Base64.decode64(parsed_data.dig('media', 'payload'))
pp "Payload: #{payload}"
@input_stream << {audio_content: payload}if payload.present?
end
end

tubesock.onclose do
p 'close'
end

tubesock.onerror do |e|
p e
end
end
end
end
end
```
Logs
[log.zip](https://github.com/googleapis/google-cloud-ruby/files/9676347/log.zip)

Ruby version: 3.1.2
Gem names, versions:
```
google-cloud-speech (1.4.0)
google-cloud-core (~> 1.6)
google-cloud-speech-v1 (>= 0.8, < 2.a)
google-cloud-speech-v1p1beta1 (>= 0.0, < 2.a)
google-cloud-speech-v1 (0.9.0)
gapic-common (>= 0.10, < 2.a)
google-cloud-errors (~> 1.0)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.