質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

解決済

1回答

844閲覧

SpeechSynthesisUtteranceでの ’ のエラー

takespring

総合スコア12

Windows 10

Windows 10は、マイクロソフト社がリリースしたOSです。Modern UIを標準画面にした8.1から、10では再びデスクトップ主体に戻され、UIも変更されています。PCやスマホ、タブレットなど様々なデバイスに幅広く対応していることが特徴です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2020/09/25 01:52

編集2020/09/25 04:27

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}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

m.ts10806

2020/09/25 01:59

実際のコードをご提示ください。
takespring

2020/09/25 04:06

簡単なコードだと読んでくれるのですが、下のようなコードだと読んでくれません。宜しくお願い致します。 'use strict'; //日本語カードの配列 const doubutsu = ['inu', 'usagi', 'ushi', 'uma', 'saru', 'neko', 'nezumi', 'kirin', 'shika', 'zou', 'buta', 'raion', 'risu', 'kaba', 'kangaru', 'kitsune', 'kuma', 'pannda', 'koara', 'gorira', 'tora', 'hitsuji', 'yagi', 'ookami', 'sai', 'shimauma', 'tanuki', 'rakuda', 'kyouryuu', 'cinpanji', 'hyou', 'koumori', 'tonakai', 'harinezumi', 'mogura', 'roba', 'sukanku', 'doubutsu', 'shippo', 'araiguma', 'musasabi', 'inoshishi', 'kamonohashi']; //フランス語の配列 const Fanimals = ['le chien', 'le lapin', 'la vache', 'le cheval', 'le singe', 'le chat', 'la souris', 'la girafe', 'le cerf', 'l\'éléphqnt', 'le cochon', 'le lion', 'l\'écureil', 'l\'hippopotame', 'les kangourous', 'le renard', 'l\'ours', 'le panda', 'le koala', 'le gorille', 'le tigre', 'le mouton', 'la chèvre', 'le loup', 'le rhinocéros', 'le zèbre', 'le blaireau', 'les chameaux', 'le dinosaure', 'le chimpanzé', 'le léopard', 'la chauve-souris', 'le renne', 'le hérisson', 'la taupe', 'l\'âne', 'la mouffette', 'les animaux', 'les queues', 'le raton laveur', 'l\'écureuil volant', 'les sangliers', 'l\'ornithorynaue']; //イタリア語の配列 const Ianimals = ['il cane', 'il coniglio', 'la vacca', 'il cavallo', 'la scimmia', 'il gatto', 'il topo', 'la giraffa', 'il cervo', 'l\'elefante', 'il maiale', 'il leone', 'lo scoiattolo', 'l\'ippopotamo', 'i canguri', 'la volpe', 'l\'orso', 'il panda', 'il koala', 'il gorilla', 'la tigre', 'la pecola', 'la capra', 'il lupo', 'il rinoceronte', 'la zebra', 'il cane procione', 'i cammelli', 'il dinosauro', 'il scimpanze', 'il leopardo', 'il pipistrello', 'la renna', 'il riccio', 'la talpa', 'l\'asino', 'la moffetta', 'gli animali', 'le code', 'il procione', 'lo scoiattolo volante', 'i cinghiali', 'l\'ornitorinco']; let matchCards = []; const jCards = doubutsu; const wCards = Fanimals; const pictures = Array.from(jCards); const answers = Array.from(wCards); //日本語カード Yates shuffle for(let i = pictures.length - 1; i >= 0; i--){ let r = Math.floor(Math.random() * ( i + 1)); const japanese = pictures[r]; jArea.insertAdjacentHTML('afterbegin', `<img src="image/doubutsu/${japanese}.jpg" id="${japanese}" onclick="imgCheck('${japanese}')">`); [pictures[i], pictures[r]] = [pictures[r], pictures[i]]; } //外国語カード Yates shuffle for(let i = answers.length - 1; i >= 0; i--){ let r = Math.floor(Math.random() * (i + 1)); const words = answers[r]; wArea.insertAdjacentHTML('afterbegin', `<button id="${words}" onclick="wordCheck('${words}')">${words}</button>`); [answers[i], answers[r]] = [answers[r], answers[i]]; } function imgCheck(japanese){ document.getElementById(japanese).style.opacity = 0.6; matchCards.unshift(japanese); jArea.style.pointerEvents = "none"; console.log(matchCards); if(matchCards.length === 2){ check(); } else { return; } } function wordCheck(words){ document.getElementById(words).style.opacity = 0.6; matchCards.push(words); wArea.style.pointerEvents = "none"; console.log(matchCards); if(matchCards.length === 2){ check(); } else { return; } } //const language = 'it-IT'; //const language = 'en-US'; //const language = 'es-ES'; const language = 'fr-FR'; //const language = 'de-DE' function disappear(){ console.log(matchCards); document.getElementById(matchCards[0]).style.display = "none"; document.getElementById(matchCards[1]).style.display = "none"; matchCards = []; } function check(){ console.log(jCards.indexOf(matchCards[0])); console.log(wCards.indexOf(matchCards[1])); if(jCards.indexOf(matchCards[0]) === wCards.indexOf(matchCards[1])){ let voice = new SpeechSynthesisUtterance(); voice.text = matchCards[1]; voice.lang = language; speechSynthesis.speak(voice); jArea.style.pointerEvents = ""; wArea.style.pointerEvents = ""; setTimeout(disappear, 1300); const pIndex = jCards.indexOf(`${matchCards[0]}.jpg`); pictures.splice(pIndex, 1); if(pictures.length === 0){ location.href = 'clear.html'; } } else { var voice = new SpeechSynthesisUtterance(); voice.text = '間違いです'; voice.lang = 'ja-JP'; speechSynthesis.speak(voice); document.getElementById(matchCards[0]).style.opacity = "initial"; document.getElementById(matchCards[1]).style.opacity = "initial"; matchCards = []; jArea.style.pointerEvents = ""; wArea.style.pointerEvents = ""; } }
m.ts10806

2020/09/25 04:07

質問は編集できますし、こちらはあくまで「質問への追記修正依頼」のコメント欄です。質問本文に追記してください。 あとコードはマークダウンのcode機能利用してくださいね。
guest

回答1

0

自己解決

途中のコードの間違いのようで、他の質問の解決からこちらも解決できそうです。ありがとうございました。

投稿2020/10/05 05:12

takespring

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問