Guest User

Untitled

a guest
Mar 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. require 'bundler/setup'
  2. require 'ffi-portaudio'
  3. require 'easy_audio'
  4. require 'google/cloud/speech'
  5.  
  6. a = []
  7. stream = EasyAudio::Stream.new(in_chans: 1) { |buffer| a.push(buffer.samples); :paContinue }
  8. stream.start
  9. stream.close
  10.  
  11. a = a.map { |arr| arr.map! {|el| el = (el * 32768).to_i }}
  12. b = a.map { |arr|
  13. arr.map! { |el|
  14. if (el < -32768)
  15. -32768
  16. elsif (el > 32767)
  17. 32767
  18. else
  19. el
  20. end
  21. }
  22. }
  23.  
  24. #There are no numbers outside the int range
  25. packed_b = b.map { |arr| arr = arr.pack("s<256") }
  26. packed_b = packed_b.join
  27.  
  28. speech = Google::Cloud::Speech.new project_id: "d1e4f76045a27474abc9384d10b800b8509c3fad", keyfile: "/Users/james/projects/uocumLudum-d1e4f76045a2.json"
  29. audio = speech.audio StringIO.new(packed_b), encoding: :linear16, sample_rate: 44100, language: "en-GB"
  30. # audio.recognize => []
Add Comment
Please, Sign In to add comment