サンジェルヴェ要塞での朝食時のGoogleCloudWebクライアントのテキスト読み上げ

非常に若い頃から、一気に三銃士を最初に読んだときから、著者は何かを学ぶための最良の方法は練習であると揺るぎなく確信しています。理論はさらに学び、研ぎ澄まされることができます、Musketeerの友人は「いくつかの素晴らしいトリックを示すでしょう」、問題ありません。しかし、由緒あるMaitre Dumas(そして著者は彼を信じています)によると、自分にとって新しいエッセンスに統合する最良の方法は、すぐに真っ逆さまにそれに突入することです。私たちのものが消えなかったところで、そしてあなたが知っているように、子供の頃からのガスコンは学者です。





, , 90% , ... , , . : , . , , , - - débutants - , , Ruby, API Google Cloud Text to Speech, PaaS- Heroku git.





. , "Is ruby dead?", , ... ----- , , , - ` , , , , /, Ruby Developer. , , "" , CTO Armand-Jean du Plessis, duc de Richelieu... , - , HR , .





. - , Human Resource, , ( - , ). ... , , , , . ", ! , !"





. - , API Google Cloud Text to Speech, - , . , , , IBM Text-to-Speech API , , , ... "" , IBM API , ( Terms of Service). , ", , " JSON, , , MasterCard . , $1, ? - , - , - , .





Free account Heroku, Ruby on Rails, git Heroku toolbelt OS.





. , rails-app, - API Google Cloud Text to Speech: device ( , , - ), , . : Heroku , email, ( , , ).





, Bootstrap 4 - ; flash- - ajax, Ruby on Rails. -, rails-app, , - " , ", ... , , . , , - .





, " ". Google-Cloud-TTS-Rails ( SSML) 18 , , , : MP3 (MPEG Audio Layer III), WAV (LINEAR16) and OGG (OGG_OPUS), voice type: WaveNet Basic. ...





... , , . , HTML (drop-down list), 0.25 4.0 ( API), 0.25, - 1.0. , :





module SoundHelper
  def speaking_rate
    select_tag 'speaking_rate', options_for_select(
      0.25.step(by: 0.25, to: 4.0), selected: '1.0'
    ), { class: 'btn' }
  end
end
      
      



, . , , , ... / , , , , . , . , in two words , Heroku , Heroku CLI git, . Ruby postgreSQL .





, :





git clone https://github.com/cmirnow/Google-Cloud-TTS-Rails.git
cd Google-Cloud-TTS-Rails
      
      



, YOUR_KEY_NAME.json, ( ). :





git add .   
git commit -m "my first commit"
heroku create
git push heroku master
heroku run rake db:migrate
      
      



Heroku, YOUR_NEW_APPLICATION -> 'Settings' -> 'Reveal Config Vars', key/value:






key: GOOGLE_APPLICATION_CREDENTIALS value: YOUR_KEY_NAME.json





key: DOMAIN_NAME value: YOUR_HEROKU_DOMAIN ### i.e 'https://***************.herokuapp.com' without quotes.





key: GMAIL_USER_NAME value: YOUR_GMAIL_LOGIN





key: GMAIL_PASSWORD value: YOUR_GMAIL_PASSWORD ### (An App Password is a 16-digit passcode that gives an app or device restricted access to your Google Account without having to divulge your personal password and complete access to your Google Account).






, , Google-Cloud-TTS-Rails , . - , . " " - 5000 , Google. , .





. rails-, , , , , :





class Validation
	include ActiveModel::Model
	attr_accessor :request
	validates :request, presence: true, length: {in:3..4999}
end
      
      



, , , TtsConversion :





  def conversion
    audio_format = TtsConversion.index(client, synthesis_input, voice, audio, params[:codec])
    success_info(audio_format)
  end

  def client
    Google::Cloud::TextToSpeech.text_to_speech
  end

  def synthesis_input
    { params[:text_or_ssml] => params[:request] }
  end

  def voice
    { language_code: params[:lang], name: params[:voicename] }
  end

  def audio
    { audio_encoding: params[:codec], speaking_rate: params[:speaking_rate].to_f }
  end
      
      



class TtsConversion
  def self.index(*args)
    response = args[0].synthesize_speech input: args[1], voice: args[2], audio_config: args[3]
    File.open 'public/output/output.' + audio_format(args[4]).to_s, 'wb' do |file|
      file.write response.audio_content
      audio_format(args[4]).to_s
    end
  end

  def self.audio_format(codec)
  	case codec
  	when "LINEAR16"
  		'wav'
    when "OGG_OPUS"
      'ogg'
  	else
  		'mp3'
  	end
  end
end
      
      



実際、すべての作業はgem'google-cloud-text_to_speech 'によって行われ、変換されたテキストと選択されたパラメーターがGoogle Cloud Text to Speech APIに渡され、音声がデジタルで返されます。おそらくそれだけです。








All Articles