{"id":330644,"date":"2022-03-15T03:00:06","date_gmt":"2022-03-15T03:00:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=330644"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=330644","title":{"rendered":"<span>\u0413\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c \u0440\u0443\u0433\u0430\u0442\u044c\u0441\u044f \u043c\u0430\u0442\u043e\u043c (\u0447\u0430\u0441\u0442\u044c 1)<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/138\/07b\/ddd\/13807bdddd4909dabdc8a24088b1ebeb.jpeg\" width=\"1600\" height=\"1066\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/138\/07b\/ddd\/13807bdddd4909dabdc8a24088b1ebeb.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041e\u0434\u043d\u0430\u0436\u0434\u044b \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0443\u0434\u043d\u043e \u0438 \u0434\u043e\u0440\u043e\u0433\u043e \u0432 \u043d\u0430\u0448\u0438 \u0434\u043d\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043f\u043e\u043f\u0430\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0435\u0435, \u0442\u043e \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0432 \u0442\u0435\u043a\u0441\u0442, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043e\u0442\u0432\u0435\u0442, \u0442\u043e\u0436\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0432\u0435\u0440\u0441\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430 &#8212; \u0432\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0441\u0435\u0431\u0435 \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u043b.<\/p>\n<h2>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/h2>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 <a href=\"https:\/\/reactjs.org\" rel=\"noopener noreferrer nofollow\"><u>React<\/u><\/a> \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/facebook\/create-react-app\" rel=\"noopener noreferrer nofollow\"><u>create-react-app<\/u><\/a> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u201c\u200b\u200bRecorderAndTranscriber\u201d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 getUserMedia \u0438\u0437 MediaDevices API \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d\u0443. \u0414\u0430\u043b\u044c\u0448\u0435 \u044d\u0442\u043e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f MediaRecorder, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0443\u0434\u0438\u043e. \u0414\u043b\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e setInterval.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/16d\/a80\/6e8\/16da806e8e90eae05f3d287460d4da21.png\" width=\"1600\" height=\"835\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/16d\/a80\/6e8\/16da806e8e90eae05f3d287460d4da21.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0432 React hook &#8212; useEffect, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"javascript\">useEffect(() => { const fetchStream = async function() {   const stream =      await navigator.mediaDevices.getUserMedia({ audio: true });      setRecorderState((prevState) => {       return {         ...prevState,         stream,       };     });   }    fetchStream(); }, []);<\/code><\/pre>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 MediaRecorder, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0442\u043e\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e.<\/p>\n<pre><code class=\"javascript\">useEffect(() => {   if (recorderState.stream) {     setRecorderState((prevState) => {       return {         ...prevState,         recorder: new MediaRecorder(recorderState.stream),       };     });   } }, [recorderState.stream]);<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0431\u043b\u043e\u043a \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430 \u0441\u0435\u043a\u0443\u043d\u0434, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u0441 \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<pre><code class=\"javascript\">useEffect(() => {   const tick = function() {     setRecorderState((prevState) => {       if (0 &lt;= prevState.seconds &amp;&amp; 59 > prevState.seconds) {         return {           ...prevState,           seconds: 1 + prevState.seconds,         };       } else {         handleStop();          return prevState;       }     });   }    if (recorderState.initTimer) {     let intervalId = setInterval(tick, 1000);     return () => clearInterval(intervalId);   } }, [recorderState.initTimer]);<\/code><\/pre>\n<p>Hook \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f initTimer, \u0430 callback \u0434\u043b\u044f setInterval \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430 \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0435\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 60 \u0441\u0435\u043a\u0443\u043d\u0434. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e 60 \u0441\u0435\u043a\u0443\u043d\u0434 \u0438\/\u0438\u043b\u0438 10Mb \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 Speech-to-Text API \u043d\u0430 \u0430\u0443\u0434\u0438\u043e \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0444\u0430\u0439\u043b\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0411\u043e\u043b\u044c\u0448\u0438\u0435 \u0444\u0430\u0439\u043b\u044b \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 Google Cloud Storage. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/cloud.google.com\/speech-to-text\/quotas\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0443\u0442<\/u><\/a>.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u044d\u0442\u043e \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u044c.<\/p>\n<pre><code class=\"javascript\">const handleStart = function() {   if (recorderState.recorder        &amp;&amp; 'inactive' === recorderState.recorder.state) {     const chunks = [];      setRecorderState((prevState) => {       return {         ...prevState,         initTimer: true,       };     });      recorderState.recorder.ondataavailable = (e) => {       chunks.push(e.data);     };      recorderState.recorder.onstop = () => {       const blob = new Blob(chunks, { type: audioType });        setRecords((prevState) => {         return [...prevState,                  {                   key: uuid(),                    audio: window.URL.createObjectURL(blob),                    blob: blob                 }                ];       });       setRecorderState((prevState) => {         return {           ...prevState,           initTimer: false,           seconds: 0,         };       });     };      recorderState.recorder.start();   } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e, \u0447\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 MediaRecorder \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0443\u0441 inactive, \u043e\u0434\u0438\u043d \u0438\u0437 <a href=\"https:\/\/www.w3.org\/TR\/mediastream-recording\/#recordingstate\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0440\u0451\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445<\/u><\/a>. \u0414\u0430\u043b\u044c\u0448\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f initTimer, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c interval. \u0427\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043b\u0441\u044f \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u0432\u0443\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ondataavailable \u0438 onstop. \u0412 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0434\u043b\u044f ondataavailable \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043a\u0443\u0441\u043e\u0447\u0435\u043a \u0430\u0443\u0434\u0438\u043e \u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432. \u0410 \u043f\u043e \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044e onstop, \u0438\u0437 \u043a\u0443\u0441\u043e\u0447\u043a\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f blod \u0444\u0430\u0439\u043b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u0441\u043f\u0438\u0441\u043a\u0443 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u0412 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e url \u043d\u0430 \u0430\u0443\u0434\u0438\u043e \u0444\u0430\u0439\u043b, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 DOM \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 audio, \u043a\u0430\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f src, \u0430 \u043f\u043e\u043b\u0435 blob, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c.<\/p>\n<h2>\u0421\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/h2>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0441\u0432\u044f\u0437\u043a\u0443 <a href=\"https:\/\/nodejs.org\" rel=\"noopener noreferrer nofollow\"><u>Node.js<\/u><\/a> \u0438 \u200b\u200b<a href=\"https:\/\/expressjs.com\" rel=\"noopener noreferrer nofollow\"><u>Express<\/u><\/a>. \u0421\u043e\u0437\u0434\u0430\u043b \u0444\u0430\u0439\u043b index.js, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438 \u0441\u043e\u0431\u0440\u0430\u043b API \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u0430) getTranscription(audio_blob_file)<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u0431) getWordErrorRate(text_from_google, text_from_human)<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u0441) getAnswer(text_from_google)<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c Word Error Rate \u044f \u0432\u0437\u044f\u043b \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 python \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/tensorflow\/lingvo\/blob\/master\/lingvo\/tasks\/asr\/tools\/simple_wer_v2.py\" rel=\"noopener noreferrer nofollow\"><u>tensorflow\/lingvo<\/u><\/a> \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043b \u0435\u0433\u043e \u0432 js. \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 <a href=\"https:\/\/leetcode.com\/problems\/edit-distance\/\" rel=\"noopener noreferrer nofollow\"><u>Edit Distance<\/u><\/a>, \u043f\u043b\u044e\u0441 \u0440\u0430\u0441\u0447\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 \u0442\u0440\u0451\u0445 \u0442\u0438\u043f\u043e\u0432: \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0437\u0430\u043c\u0435\u043d\u0430. \u042f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439, \u0447\u0442\u043e\u0431\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c \u043a <a href=\"https:\/\/cloud.google.com\/speech-to-text\/docs\/adaptation\" rel=\"noopener noreferrer nofollow\"><u>Speech-to-Text<\/u><\/a>.<\/p>\n<p>\u0414\u043b\u044f getTranscription \u044f \u0432\u0437\u044f\u043b \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a <a href=\"https:\/\/cloud.google.com\/speech-to-text\/docs\/sync-recognize\" rel=\"noopener noreferrer nofollow\"><u>Speech-to-Text<\/u><\/a>, \u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 \u0430\u0443\u0434\u0438\u043e \u0444\u0430\u0439\u043b &#8212; \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a <a href=\"https:\/\/cloud.google.com\/text-to-speech\/docs\/libraries\" rel=\"noopener noreferrer nofollow\"><u>Text-to-Speech<\/u><\/a>. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a google cloud \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442, \u043f\u043e\u0442\u043e\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c Speech-to-Text API \u0438 Text-to-Speech API, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u044e\u0447 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u043a\u043b\u044e\u0447\u0443 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e GOOGLE_APPLICATION_CREDENTIALS.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b json \u0444\u0430\u0439\u043b \u0441 \u043a\u043b\u044e\u0447\u043e\u043c, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c Service account \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cb5\/4da\/113\/cb54da1131890832378a711cfe74dbd4.png\" width=\"1600\" height=\"568\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cb5\/4da\/113\/cb54da1131890832378a711cfe74dbd4.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d0c\/4a7\/037\/d0c4a7037428b351d1604672deedc04f.png\" width=\"1410\" height=\"598\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d0c\/4a7\/037\/d0c4a7037428b351d1604672deedc04f.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7f1\/c46\/2ac\/7f1c462ac66919c6c700defbe5eed732.png\" width=\"1112\" height=\"1100\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7f1\/c46\/2ac\/7f1c462ac66919c6c700defbe5eed732.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0436\u0430\u0442\u0438\u044f Create and Continue \u0438 Done \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Credentials, \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Service Accounts \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u044d\u0442\u043e\u0442 \u0430\u043a\u043a\u0430\u0443\u043d\u0442, \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Keys \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 Add Key, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c json-\u0444\u0430\u0439\u043b \u0441 \u043a\u043b\u044e\u0447\u043e\u043c. \u042d\u0442\u043e\u0442 \u043a\u043b\u044e\u0447 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043c\u043e\u0433\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a Google Cloud \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c. \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043c\u043e\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/655653\/\"> https:\/\/habr.com\/ru\/post\/655653\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041e\u0434\u043d\u0430\u0436\u0434\u044b \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0440\u0443\u0434\u043d\u043e \u0438 \u0434\u043e\u0440\u043e\u0433\u043e \u0432 \u043d\u0430\u0448\u0438 \u0434\u043d\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043f\u043e\u043f\u0430\u0434 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b.<\/p>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0435\u0435, \u0442\u043e \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0441 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0432 \u0442\u0435\u043a\u0441\u0442, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u043e\u0442\u0432\u0435\u0442, \u0442\u043e\u0436\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0443\u0434\u0438\u043e \u0432\u0435\u0440\u0441\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430 &#8212; \u0432\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0441\u0435\u0431\u0435 \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u043b.<\/p>\n<h2>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/h2>\n<p>\u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0439 <a href=\"https:\/\/reactjs.org\" rel=\"noopener noreferrer nofollow\"><u>React<\/u><\/a> \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/facebook\/create-react-app\" rel=\"noopener noreferrer nofollow\"><u>create-react-app<\/u><\/a> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u201c\u200b\u200bRecorderAndTranscriber\u201d, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 getUserMedia \u0438\u0437 MediaDevices API \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0438\u043a\u0440\u043e\u0444\u043e\u043d\u0443. \u0414\u0430\u043b\u044c\u0448\u0435 \u044d\u0442\u043e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f MediaRecorder, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0436\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0443\u0434\u0438\u043e. \u0414\u043b\u044f \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e setInterval.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0443\u0441\u0442\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u0432 React hook &#8212; useEffect, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"javascript\">useEffect(() => { const fetchStream = async function() {   const stream =      await navigator.mediaDevices.getUserMedia({ audio: true });      setRecorderState((prevState) => {       return {         ...prevState,         stream,       };     });   }    fetchStream(); }, []);<\/code><\/pre>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 MediaRecorder, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u0442\u043e\u0436\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e.<\/p>\n<pre><code class=\"javascript\">useEffect(() => {   if (recorderState.stream) {     setRecorderState((prevState) => {       return {         ...prevState,         recorder: new MediaRecorder(recorderState.stream),       };     });   } }, [recorderState.stream]);<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0431\u043b\u043e\u043a \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430 \u0441\u0435\u043a\u0443\u043d\u0434, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u0441 \u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<pre><code class=\"javascript\">useEffect(() => {   const tick = function() {     setRecorderState((prevState) => {       if (0 &lt;= prevState.seconds &amp;&amp; 59 > prevState.seconds) {         return {           ...prevState,           seconds: 1 + prevState.seconds,         };       } else {         handleStop();          return prevState;       }     });   }    if (recorderState.initTimer) {     let intervalId = setInterval(tick, 1000);     return () => clearInterval(intervalId);   } }, [recorderState.initTimer]);<\/code><\/pre>\n<p>Hook \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f initTimer, \u0430 callback \u0434\u043b\u044f setInterval \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430 \u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0435\u0441\u043b\u0438 \u0434\u043b\u0438\u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 60 \u0441\u0435\u043a\u0443\u043d\u0434. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e 60 \u0441\u0435\u043a\u0443\u043d\u0434 \u0438\/\u0438\u043b\u0438 10Mb \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 Speech-to-Text API \u043d\u0430 \u0430\u0443\u0434\u0438\u043e \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044f \u0444\u0430\u0439\u043b\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0411\u043e\u043b\u044c\u0448\u0438\u0435 \u0444\u0430\u0439\u043b\u044b \u043d\u0443\u0436\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 Google Cloud Storage. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/cloud.google.com\/speech-to-text\/quotas\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0443\u0442<\/u><\/a>.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0442\u043e\u0438\u0442 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044c, \u044d\u0442\u043e \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430\u043f\u0438\u0441\u044c.<\/p>\n<pre><code class=\"javascript\">const handleStart = function() {   if (recorderState.recorder        &amp;&amp; 'inactive' === recorderState.recorder.state) {     const chunks = [];      setRecorderState((prevState) => {       return {         ...prevState,         initTimer: true,       };     });      recorderState.recorder.ondataavailable = (e) => {       chunks.push(e.data);     };      recorderState.recorder.onstop = () => {       const blob = new Blob(chunks, { type: audioType });        setRecords((prevState) => {         return [...prevState,                  {                   key: uuid(),                    audio: window.URL.createObjectURL(blob),                    blob: blob                 }                ];       });       setRecorderState((prevState) => {         return {           ...prevState,           initTimer: false,           seconds: 0,         };       });     };      recorderState.recorder.start();   } }<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e, \u0447\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 MediaRecorder \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0435\u0433\u043e \u0441\u0442\u0430\u0442\u0443\u0441 inactive, \u043e\u0434\u0438\u043d \u0438\u0437 <a href=\"https:\/\/www.w3.org\/TR\/mediastream-recording\/#recordingstate\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0440\u0451\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445<\/u><\/a>. \u0414\u0430\u043b\u044c\u0448\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f initTimer, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c interval. \u0427\u0442\u043e\u0431\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u044c \u044f \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043b\u0441\u044f \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u0432\u0443\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 ondataavailable \u0438 onstop. \u0412 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0434\u043b\u044f ondataavailable \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043a\u0443\u0441\u043e\u0447\u0435\u043a \u0430\u0443\u0434\u0438\u043e \u0432 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432. \u0410 \u043f\u043e \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044e onstop, \u0438\u0437 \u043a\u0443\u0441\u043e\u0447\u043a\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f blod \u0444\u0430\u0439\u043b \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u0441\u043f\u0438\u0441\u043a\u0443 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u0412 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044e url \u043d\u0430 \u0430\u0443\u0434\u0438\u043e \u0444\u0430\u0439\u043b, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 DOM \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 audio, \u043a\u0430\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f src, \u0430 \u043f\u043e\u043b\u0435 blob, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c.<\/p>\n<h2>\u0421\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/h2>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0441\u0432\u044f\u0437\u043a\u0443 <a href=\"https:\/\/nodejs.org\" rel=\"noopener noreferrer nofollow\"><u>Node.js<\/u><\/a> \u0438 \u200b\u200b<a href=\"https:\/\/expressjs.com\" rel=\"noopener noreferrer nofollow\"><u>Express<\/u><\/a>. \u0421\u043e\u0437\u0434\u0430\u043b \u0444\u0430\u0439\u043b index.js, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438 \u0441\u043e\u0431\u0440\u0430\u043b API \u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u0430) getTranscription(audio_blob_file)<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u0431) getWordErrorRate(text_from_google, text_from_human)<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u0441) getAnswer(text_from_google)<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c Word Error Rate \u044f \u0432\u0437\u044f\u043b \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 python \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <a href=\"https:\/\/github.com\/tensorflow\/lingvo\/blob\/master\/lingvo\/tasks\/asr\/tools\/simple_wer_v2.py\" rel=\"noopener noreferrer nofollow\"><u>tensorflow\/lingvo<\/u><\/a> \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043b \u0435\u0433\u043e \u0432 js. \u041f\u043e \u0441\u0443\u0442\u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 <a href=\"https:\/\/leetcode.com\/problems\/edit-distance\/\" rel=\"noopener noreferrer nofollow\"><u>Edit Distance<\/u><\/a>, \u043f\u043b\u044e\u0441 \u0440\u0430\u0441\u0447\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437 \u0442\u0440\u0451\u0445 \u0442\u0438\u043f\u043e\u0432: \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0437\u0430\u043c\u0435\u043d\u0430. \u042f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u043b\u043b\u0435\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439, \u0447\u0442\u043e\u0431\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c \u043a <a href=\"https:\/\/cloud.google.com\/speech-to-text\/docs\/adaptation\" rel=\"noopener noreferrer nofollow\"><u>Speech-to-Text<\/u><\/a>.<\/p>\n<p>\u0414\u043b\u044f getTranscription \u044f \u0432\u0437\u044f\u043b \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a <a href=\"https:\/\/cloud.google.com\/speech-to-text\/docs\/sync-recognize\" rel=\"noopener noreferrer nofollow\"><u>Speech-to-Text<\/u><\/a>, \u0430 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 \u0432 \u0430\u0443\u0434\u0438\u043e \u0444\u0430\u0439\u043b &#8212; \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043a <a href=\"https:\/\/cloud.google.com\/text-to-speech\/docs\/libraries\" rel=\"noopener noreferrer nofollow\"><u>Text-to-Speech<\/u><\/a>. \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u044b\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a google cloud \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442, \u043f\u043e\u0442\u043e\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c Speech-to-Text API \u0438 Text-to-Speech API, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043b\u044e\u0447 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u043a\u043b\u044e\u0447\u0443 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e GOOGLE_APPLICATION_CREDENTIALS.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b json \u0444\u0430\u0439\u043b \u0441 \u043a\u043b\u044e\u0447\u043e\u043c, \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c Service account \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0436\u0430\u0442\u0438\u044f Create and Continue \u0438 Done \u0432\u043e \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Credentials, \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 Service Accounts \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u0430\u043a\u043a\u0430\u0443\u043d\u0442. \u0415\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u044d\u0442\u043e\u0442 \u0430\u043a\u043a\u0430\u0443\u043d\u0442, \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 Keys \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 Add Key, \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c json-\u0444\u0430\u0439\u043b \u0441 \u043a\u043b\u044e\u0447\u043e\u043c. \u042d\u0442\u043e\u0442 \u043a\u043b\u044e\u0447 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043c\u043e\u0433\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a Google Cloud \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c, \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c. \u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043c\u043e\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043d\u0435\u043d\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043b\u0435\u043a\u0441\u0438\u043a\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/655653\/\"> https:\/\/habr.com\/ru\/post\/655653\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-330644","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=330644"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330644\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}