Please note that the translation service used in this example, MyMemory, does not require an API key, but it may have limitations and usage restrictions. If you require a more robust translation service, you may consider using a different translation API provider that suits your needs.
<!DOCTYPE html>
<html>
<head>
<title>Text-to-Speech Converter</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
h1 {
color: #333;
}
#text-input {
width: 300px;
height: 100px;
margin-bottom: 10px;
}
#language-select {
margin-bottom: 10px;
}
#speak-btn {
padding: 10px 20px;
background-color: #4CAF50;
border: none;
color: white;
font-size: 16px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Text-to-Speech Converter</h1>
<textarea id="text-input" placeholder="Enter text..."></textarea>
<label for="language-select">Select a language:</label>
<select id="language-select">
<option value="en-US">English (US)</option>
<option value="en-GB">English (UK)</option>
<option value="es-ES">Spanish (Spain)</option>
<option value="fr-FR">French (France)</option>
<!-- Add more language options as needed -->
</select>
<button id="speak-btn">Speak</button>
<script src="https://code.responsivevoice.org/responsivevoice.js?key=YOUR_API_KEY"></script>
<script>
// Ensure the ResponsiveVoice library is loaded before executing code
window.onload = function () {
var speakButton = document.getElementById("speak-btn");
speakButton.addEventListener("click", function () {
var textInput = document.getElementById("text-input").value;
var languageSelect = document.getElementById("language-select");
var selectedLanguage = languageSelect.options[languageSelect.selectedIndex].value;
responsiveVoice.speak(textInput, selectedLanguage);
});
};
</script>
</body>
</html>
No comments:
Post a Comment