junkerstock
 代読テスト01 

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>声変換・代読アプリ</title>
<style>
body { font-family: sans-serif; text-align: center; padding: 40px; background: #fdf6e3; }
.container { background: white; padding: 30px; border-radius: 20px; box-shadow: 0 10px 20px rgba(0,0,0,0.1); max-width: 600px; margin: auto; }
select, button { padding: 10px; margin: 10px; font-size: 16px; border-radius: 5px; border: 1px solid #ccc; }
button { background-color: #268bd2; color: white; cursor: pointer; border: none; }
#output { background: #eee; padding: 20px; margin-top: 20px; border-radius: 10px; min-height: 50px; }
</style>
</head>
<body>

<div class="container">
<h2>音声をテキストにして別の声で再生</h2>

<p>1. 再生する声を選んでください:</p>
<select id="voiceSelect"><option>声を読み込み中...</option></select>

<br>
<button id="startBtn">🎤 喋って声を変換する</button>

<div id="output">(ここに聞き取った内容が出ます)</div>
</div>

<script>
const voiceSelect = document.getElementById('voiceSelect');
const startBtn = document.getElementById('startBtn');
const output = document.getElementById('output');

let voices = [];

// 利用可能な「声」のリストを取得
function loadVoices() {
voices = window.speechSynthesis.getVoices();
voiceSelect.innerHTML = voices
.map((voice, index) => `<option value="${index}">${voice.name} (${voice.lang})</option>`)
.join('');
}

// 声のリストが更新されたら読み込む
window.speechSynthesis.onvoiceschanged = loadVoices;
loadVoices();

// 音声認識の設定
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.lang = 'ja-JP';

startBtn.onclick = () => {
recognition.start();
output.innerText = "聞き取り中...";
};

recognition.onresult = (event) => {
const transcript = event.results[0][0].transcript;
output.innerText = "聞き取り結果: " + transcript;

// 別の声で再生
const uttr = new SpeechSynthesisUtterance(transcript);
const selectedVoiceIndex = voiceSelect.value;
uttr.voice = voices[selectedVoiceIndex]; // 選んだ声に設定

// オプション:ピッチ(高さ)や速度を変えるとさらに別人に!
uttr.pitch = 1.2; // 0〜2 (高いほど高い声)
uttr.rate = 1.0; // 0.1〜10 (速さ)

window.speechSynthesis.speak(uttr);
};
</script>

</body>
</html>


使用変数

charset
class
id
innerHTML
innerText
lang
loadVoices -------( Function )
onclick
onresult
onvoiceschanged
output
pitch
rate
recognition
selectedVoiceIndex
SpeechRecognition
startBtn
transcript
uttr
value
voice
voices
voiceSelect