Module: SpeechCloud::Speech

Defined in:
lib/speechcloud/speech_generation.rb

Class Method Summary collapse

Class Method Details

.create_speech_file(text) ⇒ Object

Get a url for a speech file generated from uploaded text.



19
20
21
# File 'lib/speechcloud/speech_generation.rb', line 19

def create_speech_file( text )
  HTTParty.post("#{BASE_URL}/speechfiles", {:body=>get_speech_file_params( text )})
end

.create_speech_file_with_marks(text) ⇒ Object

Get a url for a speech file generated from uploaded text and for a text file with speech marks describing the positions of the text entities in a speech file.



25
26
27
# File 'lib/speechcloud/speech_generation.rb', line 25

def create_speech_file_with_marks( text )
  HTTParty.post("#{BASE_URL}/speechfileswithmarks", {:body=>get_speech_file_params( text )})
end

.delete_speech_file(file_id) ⇒ Object

Delete a single speech file data Result: success (int: 0/1) – success (1) or failure (0) of the operation



31
32
33
34
35
36
37
38
# File 'lib/speechcloud/speech_generation.rb', line 31

def delete_speech_file( file_id )
  token  = SpeechCloud::Auth.get_token
  md5    = SpeechCloud::GetMd5.formula(token)
  params = [  "token=#{token}",
              "md5=#{md5}"  ]
  params = params.join('&')
  HTTParty.delete("#{BASE_URL}/speechfiles/#{file_id}?#{params}")
end

.get_speech_file_data(file_id) ⇒ Object

Getting data of single utterance



51
52
53
54
55
56
57
58
# File 'lib/speechcloud/speech_generation.rb', line 51

def get_speech_file_data( file_id )
  token  = SpeechCloud::Auth.get_token
  md5    = SpeechCloud::GetMd5.formula(token)
  params = [  "token=#{token}",
              "md5=#{md5}"  ]
  params = params.join('&')
  HTTParty.get("#{BASE_URL}/speechfiles/#{file_id}?#{params}")
end

.get_speech_file_params(text, codec_id = 'mp3/22050') ⇒ Object

Helper. Gathers params for the create_speech_file method defined below.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/speechcloud/speech_generation.rb', line 4

def get_speech_file_params(text, codec_id='mp3/22050' )
  token        = SpeechCloud::Auth.get_token
  md5          = SpeechCloud::GetMd5.formula(token)
  content_type = 'text/plain'
  voice_id     = SpeechCloud::Config.voice_id
  codec_id     = SpeechCloud::Config.codec_id
  {  token:       token,
     md5:         md5,
     text:        text,
     contentType: content_type,
     voiceId:     voice_id,
     codecId:     codec_id  }
end

.list_speech_filesObject

Get a list of all active speech files for the current user



41
42
43
44
45
46
47
48
# File 'lib/speechcloud/speech_generation.rb', line 41

def list_speech_files
  token  = SpeechCloud::Auth.get_token
  md5    = SpeechCloud::GetMd5.formula(token)
  params = [  "token=#{token}",
              "md5=#{md5}"  ]
  params = params.join('&')
  HTTParty.get("#{BASE_URL}/speechfiles?#{params}")
end