Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'bundler/setup'
- require 'ffi-portaudio'
- require 'easy_audio'
- require 'google/cloud/speech'
- a = []
- stream = EasyAudio::Stream.new(in_chans: 1) { |buffer| a.push(buffer.samples); :paContinue }
- stream.start
- stream.close
- a = a.map { |arr| arr.map! {|el| el = (el * 32768).to_i }}
- b = a.map { |arr|
- arr.map! { |el|
- if (el < -32768)
- -32768
- elsif (el > 32767)
- 32767
- else
- el
- end
- }
- }
- #There are no numbers outside the int range
- packed_b = b.map { |arr| arr = arr.pack("s<256") }
- packed_b = packed_b.join
- speech = Google::Cloud::Speech.new project_id: "d1e4f76045a27474abc9384d10b800b8509c3fad", keyfile: "/Users/james/projects/uocumLudum-d1e4f76045a2.json"
- audio = speech.audio StringIO.new(packed_b), encoding: :linear16, sample_rate: 44100, language: "en-GB"
- # audio.recognize => []
Add Comment
Please, Sign In to add comment