You want an HTML/JS voice generator that lets the user input text, adjust speed and pitch, generate speech (using the Web Speech API or similar), and also export the audio as a WAV file for sharing. Also, you mentioned "no not supported" (likely meaning to handle browsers that don't support speech synthesis), and the URL hash "#/" (sounds like a SPA or routing detail).
Below is a complete minimal example of a voice generator with:
Text input
Speed (rate) slider
Pitch slider
A "Speak" button
Export WAV button (recording the speech output)
Handling unsupported browsers
A minimal hash routing example (#/<page>) with a default page #/
Important notes:
The Web Speech API’s speechSynthesis does not natively provide the audio as a buffer or file.
To export audio, we need to play speech through SpeechSynthesisUtterance AND record the output.
Browsers don’t provide direct output audio stream for capture from speechSynthesis.
Trick: Use the [SpeechSynthesis API + OfflineAudioContext + Web Audio API] is complicated and not well supported.
Alternative: Use speechSynthesis for playback + For export, use a TTS API that returns audio data OR polyfills like meSpeak.js or use Web Audio API speech synthesis libraries.
But for demo, I'll show a way to do "voice generation" with adjustable speed and pitch, and implement WAV export if supported via recording mic output.
Strategy for WAV export:
Use Web Audio API to create speech audio if possible OR
Record system audio is generally impossible due to permissions/security
Instead, we can record the speech synthesis playback by routing audio to an AudioContext and capturing it with a MediaStreamAudioDestinationNode.
Unfortunately, most browsers don’t expose the audio output from speech synthesis so it can be routed and recorded in JS.
Therefore, in this demo, for the Export WAV button we will fallback to "Not supported" or, alternatively, export a silent WAV file or disabled if not possible.
Demo page 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 with Speed, Pitch & Export WAV</title>
<style>
body { font-family: Arial, sans-serif; margin: 2em; max-width: 600px; }
label { display: block; margin-top: 1em; }
input[type="range"] { width: 100%; }
button { margin-top: 1em; padding: 0.5em 1em; }
.unsupported { color: red; font-weight: bold; }
</style>
</head>
<body>
<h1>Voice Generator</h1>
<div id="app"></div>
<script>
(() => {
// Simple hash routing component
function router() {
const hash = location.hash || '#/';
const app = document.getElementById('app');
if (hash === '#/' || hash === '') {
app.innerHTML = renderMain();
setupMain();
} else {
app.innerHTML = `<p>Page not found: ${hash}</p>`;
}
}
// Check support
const supportsSpeechSynthesis = 'speechSynthesis' in window && 'SpeechSynthesisUtterance' in window;
function renderMain() {
if (!supportsSpeechSynthesis) {
return `<p class="unsupported">Sorry, your browser does not support Speech Synthesis API.</p>`;
}
return `
<label>
Text to speak:
<textarea id="text" rows="4" style="width:100%" placeholder="Enter text here...">Hello world, this is a voice generator with speed and pitch control.</textarea>
</label>
<label>
Speed (Rate): <span id="rateVal">1</span>
<input type="range" id="rate" min="0.1" max="2" step="0.1" value="1" />
</label>
<label>
Pitch: <span id="pitchVal">1</span>
<input type="range" id="pitch" min="0" max="2" step="0.1" value="1" />
</label>
<button id="speakBtn">Speak</button>
<button id="exportBtn" title="Export as WAV (Not supported)">Export WAV</button>
<p id="status"></p>
`;
}
function setupMain() {
const text = document.getElementById('text');
const rate = document.getElementById('rate');
const pitch = document.getElementById('pitch');
const rateVal = document.getElementById('rateVal');
const pitchVal = document.getElementById('pitchVal');
const speakBtn = document.getElementById('speakBtn');
const exportBtn = document.getElementById('exportBtn');
const status = document.getElementById('status');
rateVal.textContent = rate.value;
pitchVal.textContent = pitch.value;
rate.oninput = () => { rateVal.textContent = rate.value; }
pitch.oninput = () => { pitchVal.textContent = pitch.value; }
speakBtn.onclick = () => {
status.textContent = '';
if (text.value.trim() === '') {
status.textContent = 'Please enter some text to speak.';
return;
}
const utterance = new SpeechSynthesisUtterance(text.value);
utterance.rate = parseFloat(rate.value);
utterance.pitch = parseFloat(pitch.value);
utterance.onstart = () => {
speakBtn.disabled = true;
status.textContent = 'Speaking...';
};
utterance.onend = () => {
speakBtn.disabled = false;
status.textContent = 'Done speaking.';
};
utterance.onerror = e => {
speakBtn.disabled = false;
status.textContent = 'Error during speech: ' + e.error;
};
window.speechSynthesis.speak(utterance);
};
// Export WAV button - This is NOT supported in speechSynthesis
exportBtn.onclick = () => {
status.textContent = 'Export WAV is not supported in this demo.';
alert('Exporting WAV from speechSynthesis output is not supported in most browsers.');
};
}
window.addEventListener('hashchange', router);
window.addEventListener('load', router);
})();
</script>
</body>
</html>
Explanation:
The UI supports input text, speed, pitch.
Clicking "Speak" uses the Web Speech Synthesis API.
Export WAV button pops a message that it's not supported because capturing speech synthesis output audio is not allowed due to browser security.
Hash (#/) routing is minimal and included.
Unsupported browser scenario is handled.
Styles are basic and minimal.
How to improve for real export functionality
Use server-side TTS APIs that return audio files for download.
Use text-to-speech libraries that create audio buffers (e.g., meSpeak.js, Amazon Polly via API).
Or record microphone input or audio context audio (not audio output) and save those.
If you want, I can prepare a demo using a client-side JavaScript TTS library that generates WAV blobs directly for download.