Friday, February 20, 2026

Text to Speech with voicerss

For an index to all my stories click this text.

This story shows how to convert text to spoken word using voicerss. This is the first in a series. This story tells how to use this service in your browser.

Some background.

I love playing with text to speech programs and services. I also think this can be a valuable addition to your projects. In the most dramatic scenario you can give spoken word feedback in your IOT projects to a blind person or a person who is visually impaired.
But there are more projects where a spoken word feedback can be valuable. And besides that it is just fun to hear your computer or microcontroller speak to you. There are several speech related projects on this weblog, but they use your phone for speech conversion.

In this and the upcoming story we are going to use a service called voicerss. And this will work on your computer but also on a microcontroller !! I will start with the computer version.

Voicerss.

Voicerss is a company that offers text to speech conversion. It is a commercial company but they have a free tier. And that tier is really generous.
You can make 350 free conversions per day and each one can have no less then 100K text. That is an awful lot for a free tier.

Even for small messages this is a lot.
350 messages a day is 14 messages per hour. But you are not likely to be awake 24 hour a day. Meaning that if you for example use this 10 hour a day you can have 35 messages per hour, meaning every 2 minutes. Well you can do the calculations yourself.

Create an account

To use voicerss there is a very simple API that can be called from a large variety of computer languages.
You do need to make an account to obtain your personal API key.


Start with visiting the Voicerss site: https://www.voicerss.org/


Chose login from the menu and at the bottom chose registration.


Fill in all the fields. You do not need to give a company name. But do fill in your real e-mail address. And of course chose an appropriate password.
Then check "I am not a robot" and press the register button at the bottom.

A confirmation email will be send to your email address. So open your email program. Look for that mail and press on the link.


The profile screen now shows at the bottom that your account is active. And it shows your API key.

The voicerss API

The API is what we need to let our computer (or microcontroller) communicate with voicerss. It is really very easy.

Look at the page with the API info.

If you scroll a bit down you can see the examples.
You can copy any one of them and just paste it into your browsers URL field.
But before pressing enter change key=1234567890QWERTY.
After the = fill in your own API key.

Then press enter. And hear the magic happening.

Experiment with this by altering the text in anything you like.

Javascript example


There are several examples at the SDK page. Just pick your preferred language and click on it.


This is the page that shows how to use voicerss with Javascript.

Start with clicking on Download Javascript text-to-speech sdk.

The download starts immediately. And a zip file will be downloaded in your computers download folder. I transferred it to a folder called voicerss I made for this article.

Clicking on that zip file reveals that it contains just a small javascript library called voicerss-tts-min.js. Extract that to the same forlder where you are going to put your own program in. This is important. The voicerss-tts-min.js library should be in the same folder where your javascript program will be. If you do not put it there your program will not be able to find the library.

At the bottom of the Javascript SDK page there is also a small example program. I downloaded that also and called it voicetest-minimal.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset='utf-8' />
    <script src='voicerss-tts.min.js'></script>
</head>
<body>
    <script>
        VoiceRSS.speech({
            key: '<API key>',
            src: 'Hello, world!',
            hl: 'en-us',
            v: 'Linda',
            r: 0,
            c: 'mp3',
            f: '44khz_16bit_stereo',
            ssml: false
        });
    </script>
</body>
</html>


Above is this program and as you can see it is very simple. That is of course because it uses the voicerss-tts-min library.

To get this working you need to change <API key> in your own API key. Only the key, do not put in the brackets.

Save the html page and then double click on it. Your browser should open saying the words Hello world. Make sure to have the volume of your speakers up.

Now this is a very simple program that can be adapted for many different projects. You could embed this in your IOT dashboards or in any project that uses Javascript to monitor or control data.

No library needed

As you have seen above you can paste the API direct in the browsers URL. So obviously using the right code you do not need the Javascript library.




I wrote a program in Javascript (and admittedly had some help with the styling). This opens a webpage with a field in which you can type text.

The code is below. Just copy it from this page. Paste it into an editor and save it as voice-test.html or something like that. Then click on that file and it will pen in your favorite browser.

Pressing the SEND button sends the text to voicerss and the program has an audio player that plays the received spoken words.
You can replay audio as often as you like by pressing the play button in the audio player.
You can of course also alter the text and resend it to voicerss.

But there is more

The received audio is also saved in your Downloads folder.
For those that wonder: my computer is a Raspberry Pi5 with 8GB and I am running Raspberry Trixie with the KDE Plasma shell. That is why the downloads folder might look unfamiliar.

Here is the program:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Text to Speech Demo</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      padding: 20px;
      background: #f9f9f9;
    }

    textarea {
      width: 100%;
      height: 150px;
      padding: 10px;
      font-size: 16px;
      border: 1px solid #ccc;
      border-radius: 5px;
      resize: vertical;
    }

    button {
      margin-top: 10px;
      padding: 10px 20px;
      font-size: 16px;
      background-color: #0078d4;
      color: white;
      border: none;
      border-radius: 5px;
      cursor: pointer;
    }

    button:hover {
      background-color: #005fa3;
    }

    audio {
      margin-top: 20px;
      width: 100%;
    }
  </style>
</head>
<body>
  <h1>Text-to-Speech (VoiceRSS)</h1>

  <textarea id="textInput" placeholder="Type your text here..."></textarea><br>
  <button id="sendButton">Send</button>

  <audio id="audioPlayer" controls></audio>

  <script>
    const button = document.getElementById('sendButton');
    const textInput = document.getElementById('textInput');
    const audioPlayer = document.getElementById('audioPlayer');

    button.addEventListener('click', async () => {
      const text = textInput.value.trim();
      if (!text) {
        alert('Please enter some text first.');
        return;
      }

      const apiKey = 'replace-with-your-key'; // replace with your real VoiceRSS key
      const language = 'en-us';
      const voice = 'Amy';

      try {
        // VoiceRSS expects a POST with form data
        const formData = new FormData();
        formData.append('key',apiKey);
        formData.append('src', text);
        formData.append('hl', language);
        formData.append('v', voice);
        formData.append('c', 'WAV'); // codec
        formData.append('f', '8khz_16bit_mono');

        const response = await fetch('https://api.voicerss.org/', {
          method: 'POST',
          body: formData
        });

        const blob = await response.blob();

        // VoiceRSS sometimes returns text error messages instead of audio
        const contentType = blob.type || '';
        if (!contentType.startsWith('audio/')) {
          const textError = await blob.text();
          console.error('VoiceRSS error:', textError);
          alert('VoiceRSS error: ' + textError);
          return;
        }

        // Create object URL for playback and saving
        const audioUrl = URL.createObjectURL(blob);

        // Play in audio element
        audioPlayer.src = audioUrl;
        audioPlayer.play();

        // Trigger file save
        const downloadLink = document.createElement('a');
        downloadLink.href = audioUrl;
        const safeText = text.slice(0, 20).replace(/[^a-z0-9]/gi, '_'); // clean name
        downloadLink.download = `tts_${safeText || 'output'}.mp3`;
        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);
      } catch (err) {
        console.error(err);
        alert('Failed to fetch or play audio.');
      }
    });
  </script>
</body>
</html>

There are just two things in this program that I want to go into detail here.

      const apiKey = 'replace-with-your-key'; // replace with your real VoiceRSS key
      const language = 'en-us';
      const voice = 'Amy';

Before running this code change 'replace-with-your-key' indeed with your own API key. 

      try {
        // VoiceRSS expects a POST with form data
        const formData = new FormData();
        formData.append('key',apiKey);
        formData.append('src', text);
        formData.append('hl', language);
        formData.append('v', voice);
        formData.append('c', 'WAV'); // codec
        formData.append('f', '8khz_16bit_mono');

        const response = await fetch('https://api.voicerss.org/', {
          method: 'POST',
          body: formData
        });

And here you can see that I did not use the Javascript library but made an ordinary fetch request.

And hey ? What's that ???
The codec is WAV and 8khz in 16 bit mono ???

Can we do something with that ??????
Well that is for another story. You'll be surprised.

The API

I urge you to look at the API page.

You can change:

- The language
- The voice male/female often multiple voices
- The audio codecs MP3/WAV/AAC/OGG/CAV
- Audio format: from 8Khz-8bit to 48Khz-44khz_16bit

Plenty of room to play around with.

Concluding

voicerss is a cloud based service and I actually lately have a dislike for cloud based services. The dislike comes from many cloud based services that suddenly shut down (dweet, original blynk, iotTweet, logitech pop etc.) or suddenly start charging for their services (IFTTT webhooks).

Nevertheless is voicerss a fun service to play with and build some projects around. I have some ideas for this and will publish them as soon as they are mature.
The API is very easy to use in all kinds of programming languages.
And most important: they have a very generous free tier which makes it possible for us mere hobbyists to build some great projects for free.

Till next time
have fun

Luc Volders









Friday, February 13, 2026

Build a webpage with Gemini AI as your oracle

For an index to all my stories click this text

This story describes how to make a webpage that displays information from Google's Gemini AI. The webpage is made with plain HTML and Javascript. You so need an API key from Google. But at the moment of this writing there are no costs involved.

The previous solution

In a previous story I demonstrated how to build a webpage with some Javascript On which you could type a question. The program send that question to an AI and the answer was written on the webpage.
You can read that story here: 
https://lucstechblog.blogspot.com/2026/02/easy-ai-with-javascript.html

Although this works flawless there are some peculiarities with the solution.
- The company that provides the service is unknown
- We do not know how generous this free service is
- We do not know what AI it uses
  update: it uses powerbrain ai which is powered by ChatGPT & GPT4
- The answers the AI provides are short.

The last point (the answers being short) does have some advantages which I am going to use in a special project. But that is for a later story.
Just be aware that that service might stop anytime.

The new solution

Some people really hate Google.
I am not one of them. They brought us great products and services like Google Search, GMail, the space for this weblog etc. And even Android. All these run for free on your devices. And yes they send you advertisements. And yes these advertisements are chosen by algorithms that look at your preferences.
And to be frank: I do not give a damn.
If advertisements pay for these free services I do not care.
Ok enough of this Google advocacy..........

There are many AI sytems around like ChatGPT, Copilot, Grok, Mistral and Gemini.

I opted for Gemini.
Gemini has a great free tier and an easy to use API.
And free really means free here. You only have to have a Google account. But if you already use Gmail or any other of their services you already have an account. So let's go.

Create an API key.



Start by visiting the Google Gemini AI developer site:
https://aistudio.google.com/welcome

At the top of the page on the right side choose Get Started


The familiar Google Sign in screen is shown and you can sigh in with your Google account (you know: xxxxxxx@gmail.com). The next screen asks for your password. Just as usual with all Google services.
If you do not own a Google Account you can create ne by clicking the text at the bottom of this screen.


When logged in look at the left side of the screen and choose the top item: API keys.
Then on the top right side click on Create API key.


A pop-up window is shown.
Fill in a name for your key and in the drop-down menu choose Default Gemini Project. Then press Create key.


The pop-up window closes and on the webpage you can see the API key is created.


Click on the blue letters of the API key AND A NEW POP-UP WINDOW APPEARS WITH ALL THE DETAILS OF YOUR api Key. There are some other details like Project name and Project number but you do ot need those now.

Copy the API key and store it somewhere safe on your computer. We will need that to get our project working.

You can also delete the key and then create a new one. You can do that if you think your key is compromised.
Make sure you never distribute any software or project that contains your own private key. Simply said: keep your API key private.

That's all you need doing to get a free API key from Google.
So click on your email adress on the bottom-left side of the page and log-out.

If you want you can have a look at the documentation page of the Gemini API. You can find all kinds of usefull information there. You can find it here:
https://ai.google.dev/gemini-api/docs

The API

Google offers a library for many languages like for example JavaScript and Python.
But we do not need it.
A simple fetch command does the trick.

Here is the complete program.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Gemini Web Chat Demo</title>
  <style>
    body {
      font-family: system-ui, sans-serif;
      background: #f7f7f7;
      padding: 2rem;
    }
    #container {
      background: #fff;
      padding: 1.5rem;
      border-radius: 8px;
      box-shadow: 0 0 10px rgba(0,0,0,0.1);
      max-width: 600px;
      margin: auto;
    }
    textarea {
      width: 100%;
      font-family: inherit;
      font-size: 1rem;
      padding: 0.6rem;
      border: 1px solid #ccc;
      border-radius: 6px;
      resize: none;           /* user can’t drag resize */
      overflow: hidden;       /* hide scrollbar */
      min-height: 2.5rem;
    }
    button {
      margin-top: 0.5rem;
      padding: 0.4rem 1rem;
    }
    #response {
      margin-top: 1rem;
      white-space: pre-wrap;
      background: #f0f0f0;
      padding: 1rem;
      border-radius: 6px;
      min-height: 100px;
    }
  </style>
</head>
<body>
  <div id="container">
    <h2>Ask Gemini</h2>
    <textarea id="userInput" placeholder="Type your question..."></textarea>
    <br>
    <button id="sendBtn">Send</button>

    <h3>Response:</h3>
    <div id="response" contenteditable="true"></div>
  </div>

  <script>
    const API_KEY = "HERE-COMES-YOUR-OWN-API-KEY"; // Replace with your key
    const MODEL = "gemini-2.5-flash";//works
    const textarea = document.getElementById("userInput");
    const sendBtn = document.getElementById("sendBtn");

    // Auto-resize textarea
    textarea.addEventListener("input", () => {
      textarea.style.height = "auto";
      textarea.style.height = textarea.scrollHeight + "px";
    });

    sendBtn.addEventListener("click", async () => {
      const input = textarea.value.trim();
      if (!input) return alert("Please enter a question.");
      const responseDiv = document.getElementById("response");
      responseDiv.textContent = "Loading...";

      try {
        const res = await fetch(
          `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent?key=${API_KEY}`,
          {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({
              contents: [{ parts: [{ text: input }] }]
            })
          }
        );

        const data = await res.json();
        const text = data?.candidates?.[0]?.content?.parts?.[0]?.text || "(No response)";
        responseDiv.textContent = text;
      } catch (err) {
        responseDiv.textContent = "Error: " + err.message;
      }
    });
  </script>
</body>
</html>


To try this program just copy it and paste it in your favorite editor. Then save it as Gemini-test.html
Next open the directory where you saved it and click on the icon. Your preferred web-browser will open with the web-page ready to use.

This will work on any webbrowser (Firefox, Chrome etc) on any operating system (Windows or Linux, have not tested on Mac but it should work)

The program is not too coplicated if you have some feeling with Javascript. It starts with HTML and CSS codes that define the page, the input field, the button and the output field.

The real magic happens in the script part and I will high-ite a few things.

    const API_KEY = "HERE-COMES-YOUR-OWN-API-KEY"; // Replace with your key
    const MODEL = "gemini-2.5-flash";

Do not forget to replace HERE-COMES-YOUR-OWN-API-KEY with your own generated API key.
I used gemini-2.5-flash as the AI system that generates my answers. But you can look up what models work in the Google AI pages.

    sendBtn.addEventListener("click", async () => {
      const input = textarea.value.trim();
      if (!input) return alert("Please enter a question.");
      const responseDiv = document.getElementById("response");
      responseDiv.textContent = "Loading...";

After putting a question in the input field you will press the Send button. This code checks if the input field is not empty before sending the data to Gemini.

      try {
        const res = await fetch(
          `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent?key=${API_KEY}`,
          {
            method: "POST",
            headers: { "Content-Type": "application/json" },
            body: JSON.stringify({
              contents: [{ parts: [{ text: input }] }]
            })
          }
        );

And here is the fetch command. It is a POST command that sends a JSON string with the contents of the input field.

        const data = await res.json();
        const text = data?.candidates?.[0]?.content?.parts?.[0]?.text || "(No response)";
        responseDiv.textContent = text;

The program then waits for a response which is also in the JSON format.
It then test if there was a valid response and if so fills the response field on the screen with the text.

Sidenote:

Javascript is really not that difficult. But it is an extensive language that can be used for many purposes. Not only for AI like this project but also for IOT projects like demonstrated in other projects on this weblog.
There are also many tricks that makes working with JavaScript a lot easier.

I have bundled more than 500 programming tricks and snippets in a book that is world-wide available through Amazon.


Click this link to learn more or to order this book.

So how does it work.

Just put a question in the input field and press the send button.
And look. Despite my spelling mistake Gemini knew what I meant.
After a short wait the answer will emerge in the response field.

As you can see the response is quite extensive.


You can also shorten the answers by altering your question in a way that Gemini forces to provide a short answer. And that is very usable for some other projects I have coming up.


Or ask Gemini to translate a sentence of text into another language.
This is a sentence from the text of this weblog.


And make me redundant.......
This is just part of the answer. The text was much longer and I got the complete HTML code with Javascript as part of the answer. 
I just needed to fill in my own API key.


And what I got, just worked fine....
I am not giving you the code. Just get your own API key and try it yourself and see what it comes up with.

Be amazed !!!

I an sure you can come up with a myriad of projects that can use this !!!

Till next time.
Have fun

Luc Volders