[{"data":1,"prerenderedAt":299},["ShallowReactive",2],{"news-item-\u002Fnews\u002Fgcp-webservice-laravel-2":3},{"id":4,"title":5,"body":6,"category":287,"created by":288,"date":289,"description":290,"extension":291,"meta":292,"navigation":135,"path":293,"sections":294,"seo":295,"stem":296,"thumbnail":297,"__hash__":298},"content_en\u002Fnews\u002Fgcp-webservice-laravel-2.md","GCP web services used Laravel framework - Part 2",{"type":7,"value":8,"toc":274},"minimark",[9,14,25,28,34,37,40,65,68,76,86,91,101,105,109,124,129,132,142,145,149,152,156,162,164,169,172,175,183,186,190,194,201,205,210,213,216,220,229,233,236,241,244,249,256,262,268],[10,11,13],"h2",{"id":12},"vi-implement-speech-to-text-api","VI. Implement Speech To Text API",[15,16,17,18],"p",{},"You can refer to this main API document ",[19,20,24],"a",{"href":21,"rel":22},"https:\u002F\u002Fcloud.google.com\u002Fspeech-to-text\u002Fdocs\u002Fquickstart-client-libraries",[23],"nofollow","page",[15,26,27],{},"Install the client library:",[15,29,30],{},[31,32,33],"code",{},"composer require google\u002Fcloud-speech",[15,35,36],{},"Now you can use Speech-to-Text to transcribe an audio file to text.",[15,38,39],{},"We will create a controller to handle 3 things:",[41,42,44,47,62],"div",{"style":43},"margin-left: 20px;",[15,45,46],{},"1. Get the uploaded audio file from the request",[15,48,49,50,54,55],{},"2. Convert audio file to ",[51,52,53],"strong",{},"FLAC"," with library ",[19,56,59],{"href":57,"rel":58},"https:\u002F\u002Fwww.ffmpeg.org\u002F",[23],[51,60,61],{},"FFMpeg",[15,63,64],{},"3. Use the below code to show the text received from Speech-to-Text API",[15,66,67],{},"In SpeechToTextController:",[69,70,72,73,75],"h3",{"id":71},"_1-convert-audio-file-received-toflacfrom-requests","1. Convert audio file received to ",[51,74,53],{}," from requests",[77,78],"img",{"className":79,"alt":83,"src":84,"style":85},[80,81,82],"block","mx-auto","mb-4","","https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170415\u002FScreen-Shot-0032-04-21-at-11.04.26.png","width: 60%;",[15,87,88],{},[51,89,90],{},"Why conversion to FLAC is necessary?",[92,93,94,98],"ul",{},[95,96,97],"li",{},"All Speech-to-Text API synchronous recognition requests must include a speech recognition config field (of type RecognitionConfig).",[95,99,100],{},"encoding  (required) specifies the encoding scheme of the supplied audio (of type AudioEncoding). If you have a choice in the codec, prefer a lossless encoding such as FLAC or LINEAR16 for best performance.",[69,102,104],{"id":103},"_2-show-the-text-received","2. Show the text received",[77,106],{"className":107,"alt":83,"src":108,"style":85},[80,81,82],"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170439\u002FScreen-Shot-0032-04-21-at-11.05.38.png",[15,110,111,112,115,116,119,120,123],{},"I create a  template with only 1 input file named “",[51,113,114],{},"Choose File","“, a button submit named “",[51,117,118],{},"Transcribe","” and a selection to select the language with default “",[51,121,122],{},"English(US)","”",[77,125],{"className":126,"alt":83,"src":127,"style":128},[80,81,82],"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25172423\u002FScreen-Shot-0032-04-21-at-11.13.52.png","width: 100%;",[15,130,131],{},"We will choose a Japanese audio file.",[133,134,137,138],"audio",{"controls":135,"style":136},true,"width: 100%","\n  ",[139,140],"source",{"src":141},"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170906\u002Fjapanese_file.mp3",[15,143,144],{},"And this is the result:",[77,146],{"className":147,"alt":83,"src":148,"style":128},[80,81,82],"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170545\u002FScreen-Shot-0032-04-21-at-11.56.52.png",[15,150,151],{},"Great! It’s works!",[10,153,155],{"id":154},"vii-implement-text-to-speech-api","VII. Implement Text To Speech API",[15,157,17,158],{},[19,159,24],{"href":160,"rel":161},"https:\u002F\u002Fcloud.google.com\u002Ftext-to-speech\u002Fdocs\u002Fquickstart-client-libraries#client-libraries-usage-php",[23],[15,163,27],{},[15,165,166],{},[31,167,168],{},"composer require google\u002Fcloud-text-to-speech",[15,170,171],{},"Now you can use Text-to-Speech to create an audio file of synthetic human speech.",[15,173,174],{},"We will create a controller to handle 2 things:",[41,176,177,180],{"style":43},[15,178,179],{},"1. Get the uploaded text file from the request",[15,181,182],{},"2. Use the below code to download an audio file received from Text-To-Speech API",[15,184,185],{},"In TextToSpeechController:",[69,187,189],{"id":188},"_1-prepare-everything-before-conversion","1. Prepare everything before conversion",[77,191],{"className":192,"alt":83,"src":193,"style":85},[80,81,82],"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170614\u002FScreen-Shot-0032-04-24-at-13.16.13.png",[15,195,196,197,200],{},"In the image above, I can set some configures for the audio file before converting, such as ",[51,198,199],{},"language, voice, gender, speed","…",[69,202,204],{"id":203},"_2-download-the-audio-file-after-conversion","2. Download the audio file after conversion",[77,206],{"className":207,"alt":83,"src":208,"style":209},[80,81,82],"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170643\u002FScreen-Shot-0032-04-24-at-13.26.44.png","width: 80%;",[15,211,212],{},"The audio file will be received with the MP3 extension.",[15,214,215],{},"Then I created a template for the Text-to-speech function. But this time, the template will be more detailed.",[77,217],{"className":218,"alt":83,"src":219,"style":128},[80,81,82],"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25173644\u002FScreen-Shot-0032-04-24-at-13.47.28-1.png",[15,221,222,223,228],{},"We will choose a Japanese text ",[19,224,227],{"href":225,"rel":226},"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F28125501\u002Fjapanese.txt",[23],"file",". And select the selections on the screen. ",[77,230],{"className":231,"alt":83,"src":232,"style":128},[80,81,82],"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170749\u002FScreen-Shot-0032-04-24-at-14.06.20.png",[15,234,235],{},"This is the result:",[133,237,137,238],{"controls":135,"style":136},[139,239],{"src":240},"https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F25170937\u002Ftext-to-speech-file.mp3",[15,242,243],{},"Awesome!!!",[15,245,246],{},[51,247,248],{},"References:",[15,250,251,252],{},"1. ",[19,253,254],{"href":254,"rel":255},"https:\u002F\u002Fcloud.google.com\u002Fvision\u002Fdocs\u002Focr#vision_text_detection-php",[23],[15,257,258,259],{},"2. ",[19,260,21],{"href":21,"rel":261},[23],[15,263,264,265],{},"3. ",[19,266,160],{"href":160,"rel":267},[23],[15,269,270,271],{},"4. ",[19,272,57],{"href":57,"rel":273},[23],{"title":83,"searchDepth":275,"depth":275,"links":276},2,[277,283],{"id":12,"depth":275,"text":13,"children":278},[279,282],{"id":71,"depth":280,"text":281},3,"1. Convert audio file received to FLAC from requests",{"id":103,"depth":280,"text":104},{"id":154,"depth":275,"text":155,"children":284},[285,286],{"id":188,"depth":280,"text":189},{"id":203,"depth":280,"text":204},"tech talk","Briswell Vietnam Co Ltd","2020-06-05","VI. Implement Speech To Text API. You can refer to this main API document page. Install the client library","md",{},"\u002Fnews\u002Fgcp-webservice-laravel-2",null,{"title":5,"description":290},"news\u002Fgcp-webservice-laravel-2","https:\u002F\u002Fhomepage-media.s3.ap-southeast-1.amazonaws.com\u002Fwp-content\u002Fuploads\u002F2020\u002F05\u002F26155516\u002F0_brH9cM9rnSRx2I-S-1.png","frQBlH-dvRyOq9dWGg3QGTCpWMP_a4vZ9-AoJpkvinc",1785320519283]