---
slug: "browser-text-to-speech-speak-as-async-await"
title: "Writing TextToSpeech in Browser Using Async Function"
description: "Run a web signage kiosk on a Raspberry Pi with Playwright + Chromium — Python script and systemd unit example."
url: "https://www.ytyng.com/en/blog/browser-text-to-speech-speak-as-async-await"
publish_date: "2023-05-03T02:47:55Z"
created: "2023-05-03T02:47:55Z"
updated: "2026-05-11T13:21:50.621Z"
categories: []
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250708/d17fb56dda584b46bab31b888260ebab.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/280/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/280/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/280/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/280/featured-music-280-1.mp3", "https://media.ytyng.net/ytyng-blog/280/featured-music-280-3.mp3"]
lang: "en"
---

# Writing TextToSpeech in Browser Using Async Function

Here's the English translation of the provided Japanese blog article:

---

This code uses the `await` keyword with the `speech` method of `SpeechSynthesisUtterance`.
It performs the text-to-speech processing in a synchronous manner in a web browser.

However, please note that due to browser security reasons, you cannot make it automatically speak as soon as the browser is opened.
The user must click a button or perform some action on the page at least once for the speech synthesis to work.

```javascript
function asyncSpeak(text) {
  const ssu = new SpeechSynthesisUtterance();
  ssu.text = text;
  ssu.lang = 'en-US';
  speechSynthesis.speak(ssu);
  return new Promise((resolve, reject) => {
    ssu.onend = () => {
      resolve();
    };
  });
}

async function onStarted() {
  await asyncSpeak('one two three four five six seven eight nine ten');
  console.log('end');
}
```

---
