Sejak usia yang sangat muda, dari pembacaan pertama The Three Musketeers dalam satu tegukan, penulis sangat yakin bahwa cara terbaik untuk mempelajari sesuatu adalah dengan berlatih. Teorinya bisa dipelajari lebih lanjut dan dipertajam, teman-teman Musketeer "akan menunjukkan beberapa trik bagus", tidak masalah. Tetapi, menurut Yang Mulia Maitre Dumas (dan penulis mempercayainya), cara terbaik untuk mengintegrasikan diri ke dalam esensi apa pun yang baru bagi diri sendiri adalah dengan segera terjun ke dalamnya, dan kemudian apa pun yang terjadi. Di mana milik kami tidak menghilang, dan, seperti yang Anda ketahui, Gascon sejak kecil adalah seorang akademisi.
, , 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
Semua pekerjaan diselesaikan, pada kenyataannya, dengan permata 'google-cloud-text_to_speech', meneruskan teks yang dikonversi dan parameter yang dipilih ke Google Cloud Text to Speech API dan menerima suara kembali dalam bentuk digital. Mungkin itu saja.