回答編集履歴
2
ちょっと修正しました
    
        answer	
    CHANGED
    
    | 
         @@ -41,7 +41,7 @@ 
     | 
|
| 
       41 
41 
     | 
    
         
             
            </body>
         
     | 
| 
       42 
42 
     | 
    
         
             
            ```
         
     | 
| 
       43 
43 
     | 
    
         
             
            停止するまで、ずっと録音状態ってことですか・・
         
     | 
| 
       44 
     | 
    
         
            -
            やったことないですが、無理やりやるとすれば以下か 
     | 
| 
      
 44 
     | 
    
         
            +
            やったことないですが、無理やりやるとすれば以下でしょうか?
         
     | 
| 
       45 
45 
     | 
    
         
             
            もっとスマートなやり方があるかもしれませんが、即席なのでご勘弁を。
         
     | 
| 
       46 
46 
     | 
    
         
             
            ```HTML
         
     | 
| 
       47 
47 
     | 
    
         
             
            <body>
         
     | 
| 
         @@ -76,12 +76,10 @@ 
     | 
|
| 
       76 
76 
     | 
    
         
             
            			recognition.start();
         
     | 
| 
       77 
77 
     | 
    
         
             
            		}
         
     | 
| 
       78 
78 
     | 
    
         
             
            		function stop() {
         
     | 
| 
       79 
     | 
    
         
            -
            			recognition.onerror = myerror;
         
     | 
| 
       80 
     | 
    
         
            -
            			recognition.abort();
         
     | 
| 
       81 
     | 
    
         
            -
            		}
         
     | 
| 
       82 
     | 
    
         
            -
            		function myerror(event) {
         
     | 
| 
       83 
79 
     | 
    
         
             
            			recognition.onend = null;
         
     | 
| 
      
 80 
     | 
    
         
            +
            			recognition.stop();
         
     | 
| 
       84 
81 
     | 
    
         
             
            		}
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
       85 
83 
     | 
    
         
             
            		function reset() { 
         
     | 
| 
       86 
84 
     | 
    
         
             
            			console.log("reset\n");
         
     | 
| 
       87 
85 
     | 
    
         
             
            			init();
         
     | 
1
追記しました
    
        answer	
    CHANGED
    
    | 
         @@ -39,4 +39,57 @@ 
     | 
|
| 
       39 
39 
     | 
    
         
             
            	</script>
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
            </body>
         
     | 
| 
      
 42 
     | 
    
         
            +
            ```
         
     | 
| 
      
 43 
     | 
    
         
            +
            停止するまで、ずっと録音状態ってことですか・・
         
     | 
| 
      
 44 
     | 
    
         
            +
            やったことないですが、無理やりやるとすれば以下かな?
         
     | 
| 
      
 45 
     | 
    
         
            +
            もっとスマートなやり方があるかもしれませんが、即席なのでご勘弁を。
         
     | 
| 
      
 46 
     | 
    
         
            +
            ```HTML
         
     | 
| 
      
 47 
     | 
    
         
            +
            <body>
         
     | 
| 
      
 48 
     | 
    
         
            +
            	<textarea id="textarea" rows=10 cols=80></textarea>
         
     | 
| 
      
 49 
     | 
    
         
            +
            	<button id="start" onclick="start()">Start</button>
         
     | 
| 
      
 50 
     | 
    
         
            +
            	<button id="stop" onclick="stop()">Stop</button>
         
     | 
| 
      
 51 
     | 
    
         
            +
            	<script>
         
     | 
| 
      
 52 
     | 
    
         
            +
            		var recognizing;
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            		init();
         
     | 
| 
      
 55 
     | 
    
         
            +
            		function init() {
         
     | 
| 
      
 56 
     | 
    
         
            +
            			window.SpeechRecognition = window.SpeechRecognition || webkitSpeechRecognition;
         
     | 
| 
      
 57 
     | 
    
         
            +
            			recognition = new webkitSpeechRecognition();
         
     | 
| 
      
 58 
     | 
    
         
            +
            			recognition.continuous = true;
         
     | 
| 
      
 59 
     | 
    
         
            +
            			recognition.lang = 'ja';
         
     | 
| 
      
 60 
     | 
    
         
            +
            			recognition.interimResults = true;
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            			recognition.onend = reset;
         
     | 
| 
      
 63 
     | 
    
         
            +
            			recognition.onresult = disp;
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            		}
         
     | 
| 
      
 66 
     | 
    
         
            +
            		function disp(event) {
         
     | 
| 
      
 67 
     | 
    
         
            +
            			var results = event.results;
         
     | 
| 
      
 68 
     | 
    
         
            +
            			for (var i = event.resultIndex; i < results.length; ++i) {
         
     | 
| 
      
 69 
     | 
    
         
            +
            				if (results[i].isFinal) {
         
     | 
| 
      
 70 
     | 
    
         
            +
            					document.getElementById('textarea').value += results[i][0].transcript + "\n";
         
     | 
| 
      
 71 
     | 
    
         
            +
            				}
         
     | 
| 
      
 72 
     | 
    
         
            +
            			}
         
     | 
| 
      
 73 
     | 
    
         
            +
            		}
         
     | 
| 
      
 74 
     | 
    
         
            +
            		function start() {
         
     | 
| 
      
 75 
     | 
    
         
            +
            			init();
         
     | 
| 
      
 76 
     | 
    
         
            +
            			recognition.start();
         
     | 
| 
      
 77 
     | 
    
         
            +
            		}
         
     | 
| 
      
 78 
     | 
    
         
            +
            		function stop() {
         
     | 
| 
      
 79 
     | 
    
         
            +
            			recognition.onerror = myerror;
         
     | 
| 
      
 80 
     | 
    
         
            +
            			recognition.abort();
         
     | 
| 
      
 81 
     | 
    
         
            +
            		}
         
     | 
| 
      
 82 
     | 
    
         
            +
            		function myerror(event) {
         
     | 
| 
      
 83 
     | 
    
         
            +
            			recognition.onend = null;
         
     | 
| 
      
 84 
     | 
    
         
            +
            		}
         
     | 
| 
      
 85 
     | 
    
         
            +
            		function reset() { 
         
     | 
| 
      
 86 
     | 
    
         
            +
            			console.log("reset\n");
         
     | 
| 
      
 87 
     | 
    
         
            +
            			init();
         
     | 
| 
      
 88 
     | 
    
         
            +
            			recognition.start();
         
     | 
| 
      
 89 
     | 
    
         
            +
            		} 
         
     | 
| 
      
 90 
     | 
    
         
            +
            		recognition.onerror = function(event)  {
         
     | 
| 
      
 91 
     | 
    
         
            +
            			console.log('音声認識エラーが検出されました:' + event.error);
         
     | 
| 
      
 92 
     | 
    
         
            +
            		}
         
     | 
| 
      
 93 
     | 
    
         
            +
            	</script>
         
     | 
| 
      
 94 
     | 
    
         
            +
            </body>
         
     | 
| 
       42 
95 
     | 
    
         
             
            ```
         
     |