Class: Miles::Stt

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/miles/stt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 80) ⇒ Stt

Returns a new instance of Stt.



10
11
12
13
14
15
# File 'lib/miles/stt.rb', line 10

def initialize(host, port=80)
	@host = host
	@port = port
	@base_uri = "#{host}#{port != 80 ? ':' + @port.to_s : ''}"
	self.class.base_uri @base_uri
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



8
9
10
# File 'lib/miles/stt.rb', line 8

def base_uri
  @base_uri
end

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/miles/stt.rb', line 8

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/miles/stt.rb', line 8

def port
  @port
end

Instance Method Details

#get_text(file_path) ⇒ Object



17
18
19
20
21
# File 'lib/miles/stt.rb', line 17

def get_text(file_path)
	contents = open(file_path, "rb") {|io| io.read }
	response = self.class.post('/recognize', :body => contents, :headers => {'Content-type' => 'audio/mpeg'})
	return JSON.parse(response.body)
end