Skip to content

Repository files navigation

att_speech

Build Status

A Ruby library for consuming the AT&T Speech API for speech to text. API details may be found here.

Installation

gem install att_speech

Usage

require'att_speech'att_speech=ATTSpeech.new({:api_key=>ENV['ATT_SPEECH_KEY'],:secret_key=>ENV['ATT_SPEECH_SECRET'],:scope=>'SPEECH'})# Read the audio file contentsfile_contents=File.read(File.expand_path(File.dirname(File.dirname(__FILE__))) + "/bostonSeltics.wav")# Blocking operationpatt_speech.speech_to_text(file_contents,type='audio/wav')# Non-blocking operation with a future, if you have a longer file that requires more processing timesleep2future=att_speech.future(:speech_to_text,file_contents,type='audio/wav')pfuture.value# Non-blocking operation that will call a block when the transcrption is returned# Note: Remember, this is a concurrent operation so don't pass self and avoid mutable objects in the block# from the calling context, better to have discreet actions contained in the block, such as inserting in a# datastoresleep2supervisor=ATTSpeech.supervise({:api_key=>ENV['ATT_SPEECH_KEY'],:secret_key=>ENV['ATT_SPEECH_SECRET'],:scope=>'SPEECH'})supervisor.future.speech_to_text(file_contents)# do other stuff heresleep5transcription=supervisor.value# returns immediately if the operation is complete, otherwise blocks until the value is readydefwrite_wav_file(audio_bytes)file_name="ret_audio-#{Time.now.strftime('%Y%m%d-%H%M%S')}.wav"full_file_name=File.expand_path(File.join(File.dirname(File.dirname(__FILE__)),'examples',file_name))audio_file=File.open(full_file_name,"w")audio_file << audio_bytesaudio_file.closeendatt_text=ATTSpeech.new({:api_key=>ENV['ATT_SPEECH_KEY'],:secret_key=>ENV['ATT_SPEECH_SECRET'],:scope=>'TTS'})# Read the text file contentstfp=File.expand_path(File.join(File.dirname(File.dirname(__FILE__)),'examples','helloWorld.txt'))txt_contents=File.read(tfp)audio=att_text.text_to_speech(txt_contents)write_wav_file(audio)# Non-blocking operation with a future, if you have a longer file that requires more processing timesleep2future=att_text.future(:text_to_speech,"This is a hello world.",type='text/plain')write_wav_file(future.value)

Copyright

Copyright (c) 2013 Jason Goecke. Copyright (c) 2014 Ben Klang. See LICENSE.txt for further details.

About

A Ruby library for consuming the AT&T Speech API for speech to text.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages