npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jstts-native

v1.0.0

Published

Biblioteca simplificada para conversão de texto em fala nativa do sistema operacional via Web Speech API.

Readme

jsTTS 🔊

jsTTS é uma biblioteca JavaScript leve e simplificada para conversão de texto em fala (Text-to-Speech), que faz a ponte direta com o motor de síntese de voz nativo do sistema operacional (como o Windows SAPI) através da Web Speech API nativa dos navegadores.


🚀 Tecnologias Utilizadas

  • JavaScript (ES6+): Manipulação do DOM, funções e controle da API de voz.
  • Web Speech API (SpeechSynthesis): Interface nativa dos navegadores web para síntese de voz.
  • Windows SAPI / System.Speech: Motor nativo do sistema operacional executado em segundo plano.
  • HTML5 & CSS3: Para páginas de demonstração e testes de interface.

🛠️ Como o Código Funciona

A função lerElemento localiza um elemento HTML através do seu seletor CSS, extrai a informação solicitada (o texto interno ou o valor de um atributo específico) e envia essa mensagem diretamente para o motor de áudio do sistema operacional.

Fluxo de Execução:

  1. Seleção do Elemento: Utiliza document.querySelector para encontrar a tag no DOM.
  2. Extração de Conteúdo:
    • Se a propriedade informada for "text" ou "innerText", captura o conteúdo textual visível do elemento (innerText).
    • Para qualquer outra propriedade (como "alt", "title", "id", "name", "src"), captura o valor do atributo via getAttribute().
  3. Gerenciamento do Motor de Áudio: Cancela leituras anteriores em andamento com speechSynthesis.cancel() para evitar sobreposição de vozes.
  4. Instanciação e Configuração: Cria um objeto SpeechSynthesisUtterance com o texto extraído e aplica as configurações de idioma (lang), velocidade (rate) e tom (pitch).
  5. Execução: Dispara a leitura com window.speechSynthesis.speak().

📦 Código da Função

function lerElemento(seletorTag, propriedade, opcoes = {}) {
  const elemento = document.querySelector(seletorTag);

  if (!elemento) {
    console.warn(`Elemento '${seletorTag}' não foi encontrado.`);
    return;
  }

  let textoParaLer = "";

  if (propriedade.toLowerCase() === "text" || propriedade.toLowerCase() === "innertext") {
    textoParaLer = elemento.innerText || elemento.textContent;
  } else {
    textoParaLer = elemento.getAttribute(propriedade);
  }

  if (!textoParaLer) {
    console.warn(`A propriedade/atributo '${propriedade}' não possui texto para leitura.`);
    return;
  }

  if (window.speechSynthesis.speaking) {
    window.speechSynthesis.cancel();
  }

  const mensagem = new SpeechSynthesisUtterance(textoParaLer);

  mensagem.lang = opcoes.lang || "pt-BR";
  mensagem.rate = opcoes.rate || 1.0;
  mensagem.pitch = opcoes.pitch || 1.0;

  window.speechSynthesis.speak(mensagem);
}

💡 Exemplos de Uso

1. Lendo o texto de um parágrafo

lerElemento("p", "text");

2. Lendo o atributo alt de uma imagem

lerElemento("img.avatar", "alt");

3. Lendo o atributo title de um botão

lerElemento("button#btn-salvar", "title");

4. Lendo o name de um campo de formulário

lerElemento("input[type='text']", "name");

5. Customizando idioma, velocidade e tom da fala

lerElemento("div.noticia", "text", {
  lang: "pt-BR",
  rate: 1.2,
  pitch: 0.9
});

⚙️ Propriedades e Opções

| Parâmetro | Tipo | Descrição | Padrão | | :--- | :--- | :--- | :--- | | seletorTag | string | Seletor CSS do elemento ("p", "#id", ".classe"). | Obrigatório | | propriedade | string | Atributo ou conteúdo a ser lido ("text", "alt", "title", "id", etc). | Obrigatório | | opcoes.lang | string | Idioma da voz a ser utilizada pelo motor de fala. | "pt-BR" | | opcoes.rate | number | Velocidade da fala (de 0.1 até 10). | 1.0 | | opcoes.pitch | number | Tom de frequência da voz (de 0 até 2). | 1.0 |


📜 Selo de Autoria

===================================================================
                         PROJETO jsTTS
             Módulo de Leitura Nativa via Web Speech API
===================================================================
  Desenvolvido por: LUKASALMEIDA
  Licença: MIT
  Compatibilidade: Navegadores Modernos (Chrome, Edge, Firefox, Safari)
  Motor de Voz: Nativo do Sistema Operacional (Windows/SAPI, macOS, Linux)
===================================================================

📄 Licença

Este projeto está sob a licença MIT. Sinta-se à vontade para usar, modificar e distribuir.