{"id":4544,"date":"2018-04-30T10:33:17","date_gmt":"2018-04-30T02:33:17","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=4544"},"modified":"2018-07-02T15:07:00","modified_gmt":"2018-07-02T07:07:00","slug":"google-cloud-speech-to-text-api","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=4544","title":{"rendered":"Google Cloud Speech to Text API"},"content":{"rendered":"<p><a href=\"https:\/\/blog.hoyo.idv.tw\/?p=3679\" target=\"_blank\" rel=\"noopener\">\u4f7f\u7528 Google Speech API \u5c07\u8a9e\u97f3\u6a94\u6848\u8fa8\u8b58\u70ba\u6587\u5b57<\/a>\u00a0\u9019\u500b\u6771\u897f\u4e0d\u51fa\u610f\u5916\u7684\u5931\u6548\u4e86\uff0cGoogle \u990a\u80a5\u8a08\u756b\u6210\u529f\u4e86\uff0c\u73fe\u5728\u5fc5\u9808\u4f7f\u7528 Google Cloud \u670d\u52d9<\/p>\n<ul>\n<li><a href=\"https:\/\/cloud.google.com\/speech-to-text\/pricing\">Pricing<\/a>\u00a0Cloud Speech-to-Text API \u50f9\u76ee\u8868\uff0c\u6bcf\u6708\u7684\u524d 60 \u5206\u9418\u514d\u8cbb\uff0c\u723e\u5f8c\u00a0\u6bcf 15 \u79d2 $0.006 \u7f8e\u5143<\/li>\n<\/ul>\n<p>\u67d0\u5929\u767c\u751f\u554f\u984c\u4e4b\u5f8c\uff0c\u56e0\u70ba\u53ea\u6709<\/p>\n<p>--<\/p>\n<h2>\u7e7c\u7e8c\u4f7f\u7528 curl \u6307\u4ee4<\/h2>\n<ul>\n<li><a href=\"https:\/\/cloud.google.com\/speech-to-text\/docs\/quickstart-protocol\">Using the Command Line<\/a><\/li>\n<\/ul>\n<p>\u5b98\u7db2\u8aaa\u660e\u4e0a\u7684\u6d41\u7a0b<\/p>\n<ol>\n<li>\u9ede\u9078 \u2192 \u9078\u64c7\u5c08\u6848 \u2192 \u4e0b\u8f09 json<\/li>\n<li><a href=\"https:\/\/cloud.google.com\/sdk\/docs\/\">Install and initialize the Cloud SDK<\/a>\u00a0\u5b89\u88dd SDK<\/li>\n<li>\u555f\u7528\u5e33\u865f<br \/>\ngcloud auth activate-service-account --key-file=[PATH]<\/li>\n<\/ol>\n<p>\u4f8b\u5916\u6574\u7406\u7684\u6d41\u7a0b\u5982\u4e0b<\/p>\n<ol>\n<li>\u5b89\u88dd Cloud SDK<\/li>\n<li>\u767b\u5165\u7d81\u5b9a Google Cloud \u5e33\u865f<\/li>\n<li>\u6e96\u5099 curl \u6240\u9700\u8cc7\u8a0a\u4e00\uff1a\u5b58\u53d6 Token<\/li>\n<li>curl \u6240\u9700\u8cc7\u8a0a\u4e8c\uff1a\u8a9e\u97f3\u67e5\u8a62 Json<\/li>\n<li>\u7d44\u5408 curl \u8a9e\u6cd5<\/li>\n<\/ol>\n<p>--<\/p>\n<h2>\u5b58\u53d6 Token<\/h2>\n<p>\u5728 Command Line \u4e0b\u57f7\u884c\u4ee5\u4e0b\u6307\u4ee4\uff0c\u6240\u4ee5\u5fc5\u9808\u4e8b\u5148\u5b89\u88dd\u00a0Cloud SDK<\/p>\n<pre class=\"lang:default decode:true\">&gt; gcloud auth print-access-token<\/pre>\n<p>\u6b63\u5e38\u60c5\u6cc1\u4e0b\u6703\u5f97\u5230\u985e\u4f3c ya29.c.El-xxxxxxxxxxxxxxx \u7684\u5b57\u4e32\uff0c\u9019\u5c31\u662f Token \u6709\u5b58\u53d6\u7684\u6642\u9593\u9650\u5236<\/p>\n<p>--<\/p>\n<h2>\u8a9e\u97f3\u67e5\u8a62 Json<\/h2>\n<p>\u57fa\u672c\u67b6\u69cb\u70ba<\/p>\n<pre class=\"lang:default decode:true \">{\r\n  \"config\": {\r\n      \"encoding\":\"FLAC\",\r\n      \"sampleRateHertz\": 16000,\r\n      \"languageCode\": \"en-US\",\r\n      \"enableWordTimeOffsets\": false\r\n  },\r\n  \"audio\": {\r\n      \"uri\":\"gs:\/\/cloud-samples-tests\/speech\/brooklyn.flac\"\r\n  }\r\n}<\/pre>\n<p>\u9810\u8a2d\u7684\u6a94\u6848\u8def\u5f91\u5b58\u653e\u5728\u00a0Google Cloud Storage \uff0c\u4e0d\u60f3\u90a3\u9ebc\u9ebb\u7169\uff0c\u6240\u4ee5\u6839\u64da<\/p>\n<ul>\n<li><a href=\"https:\/\/cloud.google.com\/speech-to-text\/docs\/reference\/rest\/v1\/RecognitionAudio\">RecognitionAudio<\/a><\/li>\n<\/ul>\n<p>\u4fee\u6539 audio \u70ba\u00a0content \uff0c\u5c07 flac \u97f3\u6a94\u8f49\u70ba base64 \u5373\u53ef\uff0c\u4ee5\u4e0b\u70ba\u7bc4\u4f8b<\/p>\n<pre class=\"lang:default decode:true\">{\r\n  \"config\": {\r\n      \"encoding\":\"FLAC\",\r\n      \"sampleRateHertz\": 44100,\r\n      \"languageCode\": \"zh-TW\",\r\n      \"enableWordTimeOffsets\": false\r\n  },\r\n  \"audio\": {\r\n      \"content\":\"....................\u7701\u7565\u5341\u842c\u5b57\u7684 Base64 \u7de8\u78bc ....RWmXOmi5Eh0J5v87fSjxg==\"\r\n  }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<h2>\u6700\u5f8c\u7684 curl \u6307\u4ee4<\/h2>\n<pre class=\"lang:default decode:true\">curl -s -H \"Content-Type: application\/json\" -H \"Authorization: Bearer ya29.c.El-xxxxxxxxxxxxxxx\" https:\/\/speech.googleapis.com\/v1\/speech:recognize -d @sync-request.json<\/pre>\n<p>\u56de\u50b3\u7d50\u679c\u4e5f\u662f Json \u683c\u5f0f\uff0c\u548c\u4ee5\u524d\u56de\u50b3\u7684 key \u7565\u6709\u4e0d\u540c<\/p>\n<pre class=\"lang:default decode:true \">{\r\n  \"results\": [\r\n    {\r\n      \"alternatives\": [\r\n        {\r\n          \"transcript\": \"\u5224\u65b7\u56de\u50b3\u6587\u5b57\"\r\n          \"confidence\": 0.93967086\r\n        }\r\n      ]\r\n    }\r\n  ]\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<h2>Google developers console API activation<\/h2>\n<pre class=\"lang:default decode:true \">{\r\n  \"error\": {\r\n    \"code\": 403,\r\n    \"message\": \"Cloud Speech API has not been used in project 32555940559 before or it is disabled. Enable it by visiting https:\/\/console.developers.google.com\/apis\/api\/speech.googleapis.com\/overview?project=32555940559 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.\",\r\n    \"status\": \"PERMISSION_DENIED\",\r\n    \"details\": [\r\n      {\r\n        \"@type\": \"type.googleapis.com\/google.rpc.Help\",\r\n        \"links\": [\r\n          {\r\n            \"description\": \"Google developers console API activation\",\r\n            \"url\": \"https:\/\/console.developers.google.com\/apis\/api\/speech.googleapis.com\/overview?project=32555940559\"\r\n          }\r\n        ]\r\n      }\r\n    ]\r\n  }\r\n}<\/pre>\n<p>\u5230 console.cloud.google.com\/apis \u7684\u6191\u8b49\uff0c\u5efa\u7acb\u65b0\u7684\u300c\u670d\u52d9\u5e33\u6236\u91d1\u9470\u300d\u4ee5\u53ca\u4e0b\u8f09\u8a72\u91d1\u9470 json \u6a94\u6848\u5f8c<\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\u555f\u7528<\/p>\n<pre class=\"lang:default decode:true\">gcloud auth activate-service-account --key-file=xxxx.json<\/pre>\n<p>&nbsp;<\/p>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4544\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;3,638&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 Google Speec...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"4544\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;3,638&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4544"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4544"}],"version-history":[{"count":12,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4544\/revisions"}],"predecessor-version":[{"id":13328,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/4544\/revisions\/13328"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}