jsでcodeを書いていて、SpeechSynthesisUtteranceで単語を読ませるようにしています。
普通の単語はうまく読んでくれるのですが、アポストロフィーを読んでくれません。
例えば、'Let's go'(英)、'l'elefante'(伊)、'l'éléphant'(仏)などは『Uncaught SyntaxError: missing ) after argument list』というエラーが出ますが、'le zèbre'(仏)はエラーも出ずに正常に動きます。それぞれの文字入力は入力法を切り替えて入力しています。使う言語は 表示言語、音声合成、音声認識、手書きなどインストール済みです。OSはWindowsです。
どのようにすれば改善するでしょうか?
javascript
1'use strict'; 2//日本語カードの配列 3const doubutsu = 4['inu', 'usagi', 'ushi', 'uma', 'saru', 'neko', 'nezumi', 'kirin', 5'shika', 'zou', 'buta', 'raion', 'risu', 'kaba', 'kangaru', 6'kitsune', 'kuma', 'pannda', 'koara', 'gorira', 'tora', 'hitsuji', 7'yagi', 'ookami', 'sai', 'shimauma', 'tanuki', 'rakuda', 'kyouryuu', 8'cinpanji', 'hyou', 'koumori', 'tonakai', 'harinezumi', 'mogura', 9'roba', 'sukanku', 'doubutsu', 'shippo', 'araiguma', 'musasabi', 10'inoshishi', 'kamonohashi']; 11 12//フランス語の配列 13const Fanimals = 14['le chien', 'le lapin', 'la vache', 'le cheval', 'le singe', 'le chat', 15'la souris', 'la girafe', 'le cerf', 'l\'éléphqnt', 'le cochon', 'le lion', 16'l\'écureil', 'l\'hippopotame', 'les kangourous', 'le renard', 'l\'ours', 17'le panda', 'le koala', 'le gorille', 'le tigre', 'le mouton', 'la chèvre', 18'le loup', 'le rhinocéros', 'le zèbre', 'le blaireau', 'les chameaux', 19'le dinosaure', 'le chimpanzé', 'le léopard', 'la chauve-souris', 'le renne', 20'le hérisson', 'la taupe', 'l\'âne', 'la mouffette', 'les animaux', 21'les queues', 'le raton laveur', 'l\'écureuil volant', 'les sangliers', 22'l\'ornithorynaue']; 23 24//イタリア語の配列 25const Ianimals = 26['il cane', 'il coniglio', 'la vacca', 'il cavallo', 'la scimmia', 27'il gatto', 'il topo', 'la giraffa', 'il cervo', 'l\'elefante', 28'il maiale', 'il leone', 'lo scoiattolo', 'l\'ippopotamo', 'i canguri', 29'la volpe', 'l\'orso', 'il panda', 'il koala', 'il gorilla', 'la tigre', 30'la pecola', 'la capra', 'il lupo', 'il rinoceronte', 'la zebra', 31'il cane procione', 'i cammelli', 'il dinosauro', 'il scimpanze', 32'il leopardo', 'il pipistrello', 'la renna', 'il riccio', 'la talpa', 33'l\'asino', 'la moffetta', 'gli animali', 'le code', 'il procione', 34'lo scoiattolo volante', 'i cinghiali', 'l\'ornitorinco']; 35 36let matchCards = []; 37 38const jCards = doubutsu; 39const wCards = Fanimals; 40const pictures = Array.from(jCards); 41const answers = Array.from(wCards); 42 43//日本語カード Yates shuffle 44for(let i = pictures.length - 1; i >= 0; i--){ 45let r = Math.floor(Math.random() * ( i + 1)); 46const japanese = pictures[r]; 47jArea.insertAdjacentHTML('afterbegin', `<img src="image/doubutsu/${japanese}.jpg" 48id="${japanese}" onclick="imgCheck('${japanese}')">`); 49[pictures[i], pictures[r]] = [pictures[r], pictures[i]]; 50} 51 52//外国語カード Yates shuffle 53for(let i = answers.length - 1; i >= 0; i--){ 54let r = Math.floor(Math.random() * (i + 1)); 55const words = answers[r]; 56wArea.insertAdjacentHTML('afterbegin', `<button id="${words}" 57onclick="wordCheck('${words}')">${words}</button>`); 58[answers[i], answers[r]] = [answers[r], answers[i]]; 59} 60 61function imgCheck(japanese){ 62document.getElementById(japanese).style.opacity = 0.6; 63matchCards.unshift(japanese); 64jArea.style.pointerEvents = "none"; 65console.log(matchCards); 66if(matchCards.length === 2){ 67check(); 68} else { 69return; 70} 71} 72 73function wordCheck(words){ 74document.getElementById(words).style.opacity = 0.6; 75matchCards.push(words); 76wArea.style.pointerEvents = "none"; 77console.log(matchCards); 78if(matchCards.length === 2){ 79check(); 80} else { 81return; 82} 83} 84//const language = 'it-IT'; 85//const language = 'en-US'; 86//const language = 'es-ES'; 87const language = 'fr-FR'; 88//const language = 'de-DE' 89 90function disappear(){ 91console.log(matchCards); 92document.getElementById(matchCards[0]).style.display = "none"; 93document.getElementById(matchCards[1]).style.display = "none"; 94matchCards = []; 95} 96 97function check(){ 98console.log(jCards.indexOf(matchCards[0])); 99console.log(wCards.indexOf(matchCards[1])); 100if(jCards.indexOf(matchCards[0]) === wCards.indexOf(matchCards[1])){ 101let voice = new SpeechSynthesisUtterance(); 102voice.text = matchCards[1]; 103voice.lang = language; 104speechSynthesis.speak(voice); 105jArea.style.pointerEvents = ""; 106wArea.style.pointerEvents = ""; 107setTimeout(disappear, 1300); 108const pIndex = jCards.indexOf(`${matchCards[0]}.jpg`); 109pictures.splice(pIndex, 1); 110if(pictures.length === 0){ 111location.href = 'clear.html'; 112} 113} else { 114var voice = new SpeechSynthesisUtterance(); 115voice.text = '間違いです'; 116voice.lang = 'ja-JP'; 117speechSynthesis.speak(voice); 118document.getElementById(matchCards[0]).style.opacity = "initial"; 119document.getElementById(matchCards[1]).style.opacity = "initial"; 120matchCards = []; 121jArea.style.pointerEvents = ""; 122wArea.style.pointerEvents = ""; 123} 124}
回答1件
あなたの回答
tips
プレビュー