Friday, 14 July 2023

language translate AI

This code sets up a language translator tool with a clean and visually appealing design. It includes CSS styling to center the text, specify fonts, and provide appropriate colors and hover effects. The JavaScript code adds event listeners to the "Translate" and "Clear" buttons and performs the translation using the MyMemory translation service API. The translated text is displayed in the target textarea, and error messages are shown in case of failures or empty input.

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

configuration of website

Menu Type: Dropdown with Full Width Ensure the navigation items in the dropdown menu contain relevant keywords related to the we...