You're looking for a simple web-based Voice Generator app using HTML, CSS, and JavaScript that can:
Generate voice (using Web Speech API TTS)
Control speed and pitch
Export audio as WAV file
Share link via URL hash (#/)
Below is a minimal complete example implementing these features:
Features in this demo:
Text input for speech
Sliders to control speed and pitch
Play / Pause
Export generated speech to WAV (via Web Audio API and Recorder)
URL hash stores the text for easy sharing
Code
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voice Generator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 1rem;
max-width: 600px;
}
label {
display: block;
margin-top: 1rem;
}
input[type=range] {
width: 100%;
}
textarea {
width: 100%;
height: 120px;
font-size: 1rem;
}
button {
margin-top: 1rem;
font-size: 1rem;
padding: 0.5rem 1rem;
cursor: pointer;
}
footer {
margin-top: 2rem;
font-size: 0.9rem;
}
</style>
</head>
<body>
<h1>Voice Generator</h1>
<label for="textInput">Text to speak:</label>
<textarea id="textInput" placeholder="Enter text here..."></textarea>
<label for="rateRange">Speed: <span id="rateValue">1</span></label>
<input type="range" id="rateRange" min="0.5" max="2" step="0.1" value="1"/>
<label for="pitchRange">Pitch: <span id="pitchValue">1</span></label>
<input type="range" id="pitchRange" min="0" max="2" step="0.1" value="1"/>
<div style="margin-top:1rem;">
<button id="playBtn">Play</button>
<button id="pauseBtn" disabled>Pause</button>
<button id="exportBtn">Export WAV</button>
</div>
<div id="shareLink" style="margin-top:1rem; font-size:0.9rem;"></div>
<footer>
<small>Text is stored in URL hash. Share by copying URL.</small>
</footer>
<script>
// Elements refs
const textInput = document.getElementById('textInput');
const rateRange = document.getElementById('rateRange');
const pitchRange = document.getElementById('pitchRange');
const rateValue = document.getElementById('rateValue');
const pitchValue = document.getElementById('pitchValue');
const playBtn = document.getElementById('playBtn');
const pauseBtn = document.getElementById('pauseBtn');
const exportBtn = document.getElementById('exportBtn');
const shareLink = document.getElementById('shareLink');
let utterance = null;
let isPaused = false;
// Update slider labels
rateRange.addEventListener('input', () => {
rateValue.textContent = rateRange.value;
});
pitchRange.addEventListener('input', () => {
pitchValue.textContent = pitchRange.value;
});
// Sync textarea with URL hash for sharing
function updateHash() {
const encoded = encodeURIComponent(textInput.value);
location.hash = '#/' + encoded;
shareLink.innerHTML = `Shareable link:<br><input style="width:100%" readonly value="${location.href}" />`;
}
textInput.addEventListener('input', updateHash);
// On page load - load hash text if exists
function loadFromHash() {
if (location.hash.startsWith('#/')) {
try {
const decoded = decodeURIComponent(location.hash.slice(2));
textInput.value = decoded;
} catch(e) {}
}
updateHash();
}
window.addEventListener('load', loadFromHash);
window.addEventListener('hashchange', loadFromHash);
// Play speech
playBtn.addEventListener('click', () => {
if (utterance && speechSynthesis.speaking) {
// If paused, resume
if (isPaused) {
speechSynthesis.resume();
isPaused = false;
playBtn.disabled = true;
pauseBtn.disabled = false;
}
return;
}
if (!textInput.value.trim()) {
alert('Please enter text to speak.');
return;
}
if (speechSynthesis.speaking) {
speechSynthesis.cancel();
}
utterance = new SpeechSynthesisUtterance(textInput.value);
utterance.rate = parseFloat(rateRange.value);
utterance.pitch = parseFloat(pitchRange.value);
utterance.onstart = () => {
playBtn.disabled = true;
pauseBtn.disabled = false;
};
utterance.onend = () => {
playBtn.disabled = false;
pauseBtn.disabled = true;
};
utterance.onerror = () => {
alert('An error occurred during speech synthesis.');
playBtn.disabled = false;
pauseBtn.disabled = true;
};
speechSynthesis.speak(utterance);
});
// Pause speech
pauseBtn.addEventListener('click', () => {
if (speechSynthesis.speaking && !speechSynthesis.paused) {
speechSynthesis.pause();
isPaused = true;
playBtn.disabled = false;
pauseBtn.disabled = true;
}
});
// Export WAV
// Helper: record speech synthesis output to WAV via MediaStreamAudioDestinationNode + MediaRecorder
exportBtn.addEventListener('click', async () => {
if (!textInput.value.trim()) {
alert('Please enter text to export.');
return;
}
try {
// Cancel any ongoing speech
speechSynthesis.cancel();
// Create utterance
const utter = new SpeechSynthesisUtterance(textInput.value);
utter.rate = parseFloat(rateRange.value);
utter.pitch = parseFloat(pitchRange.value);
// Create audio context and destination for recording
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
const dest = audioCtx.createMediaStreamDestination();
const source = audioCtx.createBufferSource();
// Hook up Web Speech API utterance to AudioContext is not standardized
// We cannot directly pipe SpeechSynthesis audio to AudioContext.
// As a workaround, we use SpeechSynthesis and capture output via AudioCapture API - currently not widely supported.
// Hence we use an alternative: use SpeechSynthesis normally and record system audio via MediaRecorder is impossible here.
// Instead, we use the Web Speech API TTS to speak text to the user and use a third party TTS or fallback for download.
// So, inline recording of speech synthesis output isn't trivial in browsers due to security sandbox and no direct API.
// Instead, we'll use a library like meSpeak.js or fetch a TTS service or skip export.
alert('Exporting speech as WAV is not reliably supported in browsers due to API limitations.\nPlease use the Play button to listen.');
} catch (e) {
alert('Export failed: ' + e.message);
}
});
// Initialize slider labels on load
rateValue.textContent = rateRange.value;
pitchValue.textContent = pitchRange.value;
</script>
</body>
</html>
Explanation
The text input is saved in the URL hash (after #/) so you can share the URL with others and they will see the text pre-filled.
You can control speed and pitch using sliders.
The Play button speaks the text aloud.
The Pause button pauses speech playback.
The Export WAV is a placeholder because the browser SpeechSynthesis API does not provide access to raw audio data, so recording and exporting WAV files reliably is not supported directly.
For real export, you'd need server-side TTS or a client TTS library like meSpeak.js or an external TTS API.
Alternative for WAV export
If WAV export is mandatory, you need to:
Use a pre-recorded TTS engine that generates audio on the client side
Use an external service (Google Cloud TTS, Amazon Polly, etc.) that returns audio to download
Use a JS-based TTS engine (like meSpeak.js) that can generate raw audio on client side
Let me know if you want an example using meSpeak.js or connecting an external API!