# Read Aloud for Umbraco Add "listen to this article" to an Umbraco site. By default the reader's browser speaks the text with its own built-in voice. For natural neural voices with word highlighting, add the Azure package. Audio from the server is cached on your own server. The only thing kept about listening is a count per page, voice and day, and nothing that says who listened. For Umbraco 16, 17 and 18, on .NET 9 and .NET 10. ``` dotnet add package BaryoDev.Umbraco.ReadAloud ``` Nothing else to run: the package registers itself through an Umbraco composer, and every setting has a working default. --- ## Voices By default the package uses the browser's built-in voice. Nothing is synthesized on your server and nothing is sent to a third party. Quality depends on the device: good on iPhone, Mac and recent Android, robotic on many Windows and Linux machines. Word highlighting is less precise than with a server voice. For natural neural voices with word highlighting, install `BaryoDev.Umbraco.ReadAloud.Azure`, then paste the Speech key into the Read Aloud dashboard in the Settings section. No server access and no restart. Configuration can set the key instead. See [Azure AI Speech](#azure-ai-speech). The Azure free tier is 500,000 characters a month. If a server voice fails at runtime, the route answers 503 and the browser falls back to its own voice. ## What it does - A `` element that reads a configured property of the current page - Word-by-word highlighting driven by real timings from the engine, not estimates - Audio cached on disk, so the same article is never synthesized twice - Lazy generation, so publishing is instant and nothing is synthesized until somebody asks ## Usage Load the client on any page you want a button on, then add the element: ```html ``` - `node`: the published content key of the page to read. Required - `for`: a selector to the element whose words get highlighted as they are spoken, and whose text is read by the `speechSynthesis` fallback if the server route fails. Optional; without it the button still plays, just without highlighting - `voice`: optional, honoured only if the site's configuration allows it - `base`: optional path prefix for a site not mounted at the root (an IIS virtual application, `UsePathBase`, and similar). The client works the prefix out from the URL this script was served from, so it is only needed if you serve the file from somewhere other than `App_Plugins` No build step: the file above is a plain ES module, committed as-is in the package. ## What it does not do - **Store anything about a listener.** No IP, no user agent, no identity, no cookie. The only things written are derived audio you can delete at any time and a table of listen counts (see [Listen counts](#listen-counts)) - **Call any third party except the speech service itself.** No analytics, no telemetry - **Require a build step.** No npm, no bundler ## Configuration v1 is configuration only. Every value has a working default. ```json "BaryoDev": { "ReadAloud": { "Enabled": true, "DocumentTypes": [ "article", "blogPost" ], "PropertyAlias": "bodyText", "DefaultVoice": "en-GB-SoniaNeural", "AllowedVoices": [ "en-GB-SoniaNeural", "en-US-JennyNeural", "fil-PH-BlessicaNeural" ], "VoicePropertyAlias": "readAloudVoice", "DisablePropertyAlias": "readAloudDisabled", "MaxChars": 8000, "CachePath": "App_Data/BaryoDev/ReadAloud", "CacheMaxAgeDays": null, "FailureBackoffSeconds": 30, "AuthFailureBackoffSeconds": 300, "CountListens": true, "RateLimitPerMinute": 20, "MaxConcurrentSynthesis": 4, "Provider": "Browser" } } ``` ### Per-page voice and switch Editors can pick a voice for one page, or turn read-aloud off for it. Add either property, or both, to the document type. Nothing changes for a page that has neither. For the voice, first create a data type in Settings, Data Types, using the property editor UI "Read Aloud voice". Then add a property of that data type to the document type with the alias `readAloudVoice`. - Voice: the property with the alias `readAloudVoice` uses that data type. It lists "Use the site default" and your `AllowedVoices`. With the Azure package active and a voice list for the region, only the voices the region offers are shown. Empty means use the site setting, never off. - Off: add a property with the alias `readAloudDisabled` and the built-in True/false editor (`Umbraco.TrueFalse`). When it is on, both routes answer 404 like a document type that is not listed, and the button on the page removes itself. Unset or off means the page is read. Order of choice: the page voice, then the voice in the `voice` attribute, then `DefaultVoice`. A page voice has to be in `AllowedVoices` (or be `DefaultVoice`). Otherwise it is ignored, a warning is logged and the site setting applies, so an editor cannot pick a voice you did not allow. An empty `AllowedVoices` means the default voice only, so a page voice is ignored then too. Each voice has its own cached audio. Use other aliases with `VoicePropertyAlias` and `DisablePropertyAlias`, or set either to an empty string to ignore it. The voice list for the editor is `GET /umbraco/management/api/v1/baryodev/read-aloud/voices`. It needs a backoffice login with access to the Content section, which is the section editors work in and does not need Settings access. ### Provider `"Browser"` is the default, so there is nothing to set. `"Azure"` needs the [Azure package](#azure-ai-speech). `"Edge"` was removed because Microsoft rejects its requests. A site that still sets it runs as `"Browser"` and logs one warning at startup. It becomes a startup error in 1.0. A value with no provider behind it, or `"Azure"` with the package missing, or with no key in configuration and none saved in the backoffice, stops the site at startup with a message naming the setting. To synthesize somewhere else, register your own `IReadAloudEngine` (after the package's composers, so yours is the one resolved). A registered engine runs whatever `Provider` says, and caches under the configured `Provider` unless it overrides `IReadAloudEngine.Provider`. With the Azure package installed, the voice is chosen on every request, so a key saved or removed in the backoffice applies to the next request. Without it, the engine is chosen once, when the site starts, and changing `Provider` needs a restart. With `"Browser"` nothing is synthesized: no outbound call and no text extraction. The page checks run first, so a protected, unlisted or switched-off page is a 404 and a readable one a 503, and the client script speaks with `speechSynthesis`. The client makes one small request per page and then stays on the browser voice. The provider is part of the cache key, so switching it does not serve audio or timings made by the other one. The first request for each article after a switch synthesizes again. Cache files made by 0.1.x are never read again (the key now includes the provider), so the cache folder can be cleared. ## Azure AI Speech Microsoft's supported speech service, with the same neural voices (for example `en-PH-RosaNeural`). Use it when you want server-made audio with a contract behind it. ``` dotnet add package BaryoDev.Umbraco.ReadAloud.Azure ``` ### Create your own Speech resource You own the resource and the key. The free F0 tier is enough for most sites. [![Create a Speech resource in Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FBaryoDev%2Fumbraco-read-aloud%2Fmain%2Fazure%2Fspeech-resource.json) The button opens the Azure portal with [`azure/speech-resource.json`](azure/speech-resource.json), a template that creates one Speech resource (F0 by default, S0 if you pick it). The template returns no key. After it finishes: 1. Open [your Azure AI services](https://portal.azure.com/#browse/Microsoft.CognitiveServices%2Faccounts) and open the new resource. 2. Go to Keys and Endpoint. Copy Key 1 and Location. 3. Paste them into the Read Aloud dashboard (below). Or with the Azure CLI. Replace the names in angle brackets. ``` az cognitiveservices account create --name --resource-group --kind SpeechServices --sku F0 --location --yes az cognitiveservices account keys list --name --resource-group --query key1 -o tsv ``` An F0 resource is limited to one per subscription. If Azure refuses it, use `--sku S0`. Then set the key in either of two ways. ### In the backoffice (the normal way) Open Settings, then the Read Aloud tab. Pick the region of the resource (or "Other" for one that is not listed) and paste the key, press Test, then Save. Readers get the Azure voice from the next request. Remove puts the browser voice back, also with no restart. Only users with access to the Settings section can open it, and the API behind it checks the same permission. - Test asks Azure for the voice list of that region with what you typed, or with the saved key if the key box is empty. It saves nothing. It says "Azure accepted the key for {region}. N voices available" (listing voices does not prove your quota or synthesis works), or that Azure refused the key (Azure answers a wrong key and a wrong region the same way, so the message names both), or that Azure could not be reached. - The dashboard also lists your `DefaultVoice` and `AllowedVoices` and marks any the region does not offer. - The key is write-only. The dashboard and the API only say whether a key is saved and which region it is for. Nothing returns the key or part of it, and it is never logged. - Leave the key box empty on Save to keep the saved key and change only the region. The key is stored encrypted in the Umbraco database (the `umbracoKeyValue` table) with ASP.NET Core Data Protection. It uses a key ring of its own, kept in `umbraco/Data/DataProtection-Keys/ReadAloud` under the site root (set `BaryoDev:ReadAloud:KeysPath` to move it). **Keep that folder across deploys.** If it is lost or the database is copied to a site without it, the saved key cannot be read: readers get the browser voice, the dashboard says "Saved key can no longer be read, enter it again", and entering it again fixes it. The ring is plain key files on disk, so someone who can read both the database and that folder can decrypt the key. With several servers behind a load balancer, point `KeysPath` at a folder they share. A change made on one server reaches the others within about 15 seconds. ### In configuration (an override) If configuration supplies a key, it wins. The dashboard then shows that the key is set by configuration and turns off Save and Remove. ```json "BaryoDev": { "ReadAloud": { "Provider": "Azure", "DefaultVoice": "en-PH-RosaNeural", "AllowedVoices": [ "en-PH-RosaNeural" ], "Azure": { "Region": "southeastasia" } } } ``` **The key goes in an environment variable or user secrets, never in an `appsettings` file that is committed to git.** ``` BaryoDev__ReadAloud__Azure__Key= ``` ``` dotnet user-secrets set "BaryoDev:ReadAloud:Azure:Key" "" ``` Order of precedence: a key from configuration (with `Provider` set to `"Azure"`), then the key saved in the backoffice, then the browser voice. A key in configuration is ignored while `Provider` is not `"Azure"`, and the dashboard says so. A site with `Provider` left at `"Browser"` and a key saved in the backoffice gets Azure. Startup: `Provider: "Azure"` with no key in configuration and no saved key stops the site at startup and names the setting, not the value. With a saved key it boots, and that includes a saved key that can no longer be decrypted: startup only checks that a record exists, so a lost key ring does not stop the site. Readers get the browser voice and the dashboard asks for the key again. A region must be a region id as Azure writes it: 1 to 63 lowercase letters and digits, such as `southeastasia` or `westus3`. A site with no Azure settings at all always boots. ### Voice list With Azure active, the package fetches the voice list of your region once a day and keeps it in memory (a failed fetch is retried after a couple of minutes). If `DefaultVoice` or any `AllowedVoices` entry is not in the list, it logs one warning naming them. An unreachable list never stops startup or a page. Without the Azure package the dashboard says to install it and shows no fields. The free F0 tier of Azure AI Speech includes 500,000 neural characters a month. Check Azure's pricing page for the current figure, since it is Microsoft's to change. Audio is cached on your server, so each article is synthesized once per voice and edit. **Why a separate package.** It uses the official Speech SDK, because word-by-word highlighting needs real WordBoundary timings and the plain REST endpoint does not return them. The SDK ships native binaries. Keeping it out of the core means sites on the browser voice do not carry them. Failures: the route answers 503 and the browser falls back to `speechSynthesis`. The audio is `audio-24khz-48kbitrate-mono-mp3`, the same format the browser client already plays. ### Listen counts `CountListens` (default `true`) counts plays. After the update a site counts plays unless `CountListens` is false. It can be switched off at runtime; held counts are then dropped and nothing more is written. **What is counted.** One count each time the audio route answers a play with a 200 or a 304. The timings route, refusals, 404s, failures and browser-voice mode count nothing. A request with a `Range` header counts only when it is `bytes=0-`, so a seek or a probe does not add a play. A count is a request, not a person. Bots and link previews that fetch the audio are counted. A play is counted when the 200 or 304 is returned, not when it is delivered or heard. **What is stored.** One table, `baryoReadAloudListens`, with four columns: the node key, the voice actually used, the UTC day as `yyyymmdd`, and the count. No IP, no user agent, no identity, no cookie, no time of day. Nothing in it says who listened. **What this does not see.** - A CDN or proxy that answers for the origin hides those plays. The count is plays that reached the server. - Your web server's request log still records every request, with whatever it logs. This package does not control that. - A crash or a hard stop loses up to a minute of counts. They are held in memory and written once a minute and again at shutdown. A shutdown waits at most five seconds. - Rows for a node that is later deleted stay. Nothing removes them. **Read the counts.** ```sql SELECT NodeKey, Voice, SUM(Listens) AS Listens FROM baryoReadAloudListens GROUP BY NodeKey, Voice ORDER BY Listens DESC; ``` **Prune old days.** There is no retention setting. Delete what you do not want (`20260101` is a day, as a number): ```sql DELETE FROM baryoReadAloudListens WHERE DayUtc < 20260101; ``` **The table is created by a package migration**, on every install including sites that use the browser voice. Umbraco runs it at startup when `Umbraco:CMS:Unattended:PackageMigrationsUnattended` is true, which is the default. If you set it to false, the table is not created until you run the package migration yourself (for example by setting it to true for one start). Until it does, counts stay in memory, the flush logs one warning per failure streak, and nothing else breaks. Umbraco itself logs the database error for each failed statement, next to the package's one warning per streak. Voices longer than 100 characters in `DefaultVoice` or `AllowedVoices` are refused at startup because the column holds 100. **On Umbraco 17 and 18, a site with `Umbraco:CMS:ModelsBuilder:ModelsMode` set to `InMemoryAuto` needs the `Umbraco.Cms.DevelopmentMode.Backoffice` package.** Without it, the start that runs this package's migration fails. The next start works. This is Umbraco's own check, and any package migration triggers it. **Remove it.** Set `CountListens` to `false`, uninstall the package, then `DROP TABLE baryoReadAloudListens`. Umbraco keeps the migration state for the plan `BaryoDev.Umbraco.ReadAloud` in `umbracoKeyValue`. Remove that row too if you reinstall and want the migration to run again. ### RateLimitPerMinute and what "per IP" means The limit is a fixed one-minute window per source IP **as the server sees it**, which is the address of whatever connected to it. On a site behind Cloudflare, nginx, a load balancer or any other reverse proxy, that is the edge's address and not the reader's, so every visitor on the site shares a single bucket and ordinary readers start getting `429 Too Many Requests`. If your site sits behind a proxy, configure ASP.NET's forwarded headers middleware (`UseForwardedHeaders`, with `ForwardedHeaders.XForwardedFor`) and restrict it to your proxy's addresses. Without it this setting does not do what its name suggests, and raising the number only delays the problem. The address is used as an in-memory partition key for the length of one window. It is never written to disk, never logged, and never part of a cache key. ### Caching Both routes send a strong `ETag` (from the synthesis cache key, different for audio and timings) and `Cache-Control: private, no-cache`. A replay sends `If-None-Match` and gets a 304 with no body instead of the whole file. The 304 is decided after the public access, published and document type checks, so a protected page answers the same with or without a tag. A 304 still counts against `RateLimitPerMinute`. There is no `max-age`: the URL does not change when an article is edited, so a browser or CDN must ask the origin each time. Error responses carry no `ETag`. ### MaxConcurrentSynthesis A ceiling on how many articles are being synthesized at once across the whole site, which is a different quantity from the rate limit: the rate limit counts requests arriving, and one synthesis of a long article outlives the request that asked for it, deliberately, so the cache is filled for whoever asks next. Past the ceiling a request is refused with a 503 and the reader gets the browser's own voice, rather than waiting on a queue with no end. Four is deliberately modest, because a burst of connections is what gets a service to throttle you. ### Failure backoff After a synthesis fails, requests for the same text within `FailureBackoffSeconds` (default 30) skip the speech service and answer the same 503, so the browser voice takes over without another paid call. When Azure rejects the key (401 or 403), every request skips it for `AuthFailureBackoffSeconds` (default 300) and one warning is logged. On a 429 the same applies to every key for the service's Retry-After, capped at 300 seconds, or `FailureBackoffSeconds` when it sends none. Set a value to 0 to turn that backoff off. A 429 Retry-After is still honoured when `FailureBackoffSeconds` is 0. Saving or removing the Azure key in the backoffice clears every backoff at once. Audio already cached is still served. Failures are remembered in memory only, at most 1000 keys. A custom engine can report these cases by throwing `SynthesisRejectedException`. The Azure package does. ### Cleaning up the cache Cache files are named by a hash of the text, so editing a page makes a new file and leaves the old one. Files for edited, unpublished and deleted pages stay until swept or until you delete the folder, which is always safe. To sweep, set `CacheMaxAgeDays`, for example `30` (1 to 36500). Once a day a background job deletes cached files last written more than that many days ago, in batches of 500, and the next request for a deleted entry makes it again. It is off by default and only touches files named like cache entries. It runs only when the registered `IAudioCache` also implements `IAudioCacheSweep`, which the built-in disk cache does. The file time is the last write, because the disk cache does not record reads, so a popular article is regenerated once per window. ## Related The browser half comes from [`@baryodev/read-aloud`](https://www.npmjs.com/package/@baryodev/read-aloud), which is published and framework-agnostic. This package is the Umbraco-side sibling: it reads the property server-side, which is the thing a framework-agnostic package cannot do. ## Contributing Genuinely welcome, including small changes. See [CONTRIBUTING.md](https://github.com/BaryoDev/umbraco-read-aloud/blob/main/CONTRIBUTING.md), and look for [`good first issue`](https://github.com/BaryoDev/umbraco-read-aloud/labels/good%20first%20issue). ## Licence [MIT](https://github.com/BaryoDev/umbraco-read-aloud/blob/main/LICENSE)