article-voice 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +105 -94
- package/dist/index.d.ts +15 -4
- package/dist/index.js +232 -40
- package/dist/index.js.map +1 -1
- package/package.json +24 -26
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Moises Baldenegro Melendez
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Moises Baldenegro Melendez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,94 +1,105 @@
|
|
|
1
|
-
# article-voice
|
|
2
|
-
|
|
3
|
-
**Que cualquier artículo se pueda escuchar.** Un componente web (`<article-voice>`) que detecta el
|
|
4
|
-
artículo de la página y lo lee en voz alta. Funciona con cualquier framework o sin ninguno.
|
|
5
|
-
|
|
6
|
-
>
|
|
7
|
-
>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
| `moss-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Con
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
# article-voice
|
|
2
|
+
|
|
3
|
+
**Que cualquier artículo se pueda escuchar.** Un componente web (`<article-voice>`) que detecta el
|
|
4
|
+
artículo de la página y lo lee en voz alta. Funciona con cualquier framework o sin ninguno.
|
|
5
|
+
|
|
6
|
+
> Consulta la [versión disponible en npm](https://www.npmjs.com/package/article-voice) y las
|
|
7
|
+
> [novedades de cada versión](CHANGELOG.md).
|
|
8
|
+
|
|
9
|
+
## Motores de voz
|
|
10
|
+
|
|
11
|
+
| Motor (`engine`) | Estado | Qué hace |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| `moss-server` | **Recomendado** | Voz neuronal [MOSS-TTS-Nano](https://github.com/OpenMOSS/MOSS-TTS-Nano) generada por **tu propio servidor**, compatible con OpenAI `/v1/audio/speech`. El visitante no descarga nada. Requiere `server-url`. Guía: [levantar tu servidor](docs/07-operacion/moss-server.md) y [ejemplo](examples/moss-server). |
|
|
14
|
+
| `web-speech` | Respaldo | Voces locales del sistema (`speechSynthesis`). La calidad y los idiomas dependen del dispositivo. |
|
|
15
|
+
| `moss-browser` | **Experimental, solo en el spike** | El runtime de MOSS en el navegador está en [`spikes/t000-moss-browser`](spikes/t000-moss-browser) y queda fuera del paquete distribuido. |
|
|
16
|
+
|
|
17
|
+
Con `engine="auto"` (por defecto) se usa `moss-server` si hay `server-url` y responde; si no, se
|
|
18
|
+
usa la voz del sistema y el componente lo indica (evento `article-voice:fallback`). Con
|
|
19
|
+
`moss-server`, el texto va al servidor que configuras. Con `web-speech`, el texto se procesa
|
|
20
|
+
en el dispositivo con las voces locales disponibles.
|
|
21
|
+
|
|
22
|
+
Si solicitas `engine="moss-browser"` en `<article-voice>`, con el respaldo permitido y una voz
|
|
23
|
+
local disponible el elemento usa `web-speech`, reporta `activeEngine` como
|
|
24
|
+
`{ kind: 'web-speech', fallback: true }` y muestra «Se usa la voz del sistema». También emite
|
|
25
|
+
`article-voice:fallback` con el motivo `moss-browser-unavailable`. Con `fallback="none"` emite
|
|
26
|
+
`AV_ENGINE_UNAVAILABLE`, deja `activeEngine` en `null` y no sintetiza.
|
|
27
|
+
|
|
28
|
+
## Instalar y usar
|
|
29
|
+
|
|
30
|
+
Con npm:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
npm install article-voice
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import 'article-voice'; // registra <article-voice>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<article-voice server-url="https://tts.example.com"></article-voice>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Sin bundler, usa el módulo ES desde el CDN:
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/article-voice@0.1.0/dist/index.js"></script>
|
|
48
|
+
<article-voice server-url="https://tts.example.com"></article-voice>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Sin `server-url` el componente lee con la voz del sistema. Un artículo concreto se indica con
|
|
52
|
+
`for="id"` o `target="selector"`.
|
|
53
|
+
|
|
54
|
+
En la versión 0.2.0, pendiente de publicación en npm, `web-speech` ofrece las voces locales que el
|
|
55
|
+
navegador tenga disponibles y prioriza las del idioma del artículo. Por defecto elige una variante
|
|
56
|
+
identificada como Premium, Enhanced, Natural o Neural
|
|
57
|
+
cuando existe. Si no hay una variante mejorada, prioriza la voz predeterminada del navegador entre
|
|
58
|
+
las voces disponibles. Una selección guardada o un atributo `voice` válido puede cambiar esa elección.
|
|
59
|
+
|
|
60
|
+
### Atributos principales
|
|
61
|
+
|
|
62
|
+
| Atributo | Valores | Por defecto | Descripción |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `server-url` | URL https | — | Servidor para `moss-server` |
|
|
65
|
+
| `engine` | `auto` \| `moss-server` \| `web-speech` \| `moss-browser` | `auto` | Motor preferido |
|
|
66
|
+
| `fallback` | `web-speech` \| `none` | `web-speech` | Respaldo si falla el motor |
|
|
67
|
+
| `for` / `target` | id / selector CSS | — | Artículo explícito |
|
|
68
|
+
| `lang` | BCP 47 | del artículo | Fuerza el idioma |
|
|
69
|
+
| `voice` | id de voz | la primera disponible en el motor | Voz del navegador o de `moss-server`. La 0.2.0 descubre voces del servidor en `GET /v1/audio/voices`. |
|
|
70
|
+
| `rate` | 0.75–2.0 | 1 | Velocidad |
|
|
71
|
+
| `min-words` | entero | 120 | Mínimo de palabras para ofrecer el botón |
|
|
72
|
+
|
|
73
|
+
Un valor inválido emite `AV_INVALID_OPTION` y se usa el valor por defecto. Lista completa,
|
|
74
|
+
propiedades, métodos, eventos y estilos en el
|
|
75
|
+
[contrato de la API](docs/04-diseno/contrato-api-publica.md); errores en el
|
|
76
|
+
[catálogo](docs/04-diseno/catalogo-de-errores.md). Algunos atributos del contrato (resaltado de la
|
|
77
|
+
frase) aún están en el backlog.
|
|
78
|
+
|
|
79
|
+
## Documentación
|
|
80
|
+
|
|
81
|
+
- **Por qué existe y para quién:** [visión](docs/01-producto/vision.md), [PRD](docs/01-producto/prd.md)
|
|
82
|
+
- **Qué debe hacer:** [requisitos](docs/02-requisitos/srs.md), [historias](docs/02-requisitos/historias-de-usuario.md)
|
|
83
|
+
- **Cómo está hecho y por qué:** [SAD](docs/03-arquitectura/sad.md) y [ADRs](docs/03-arquitectura/adr/README.md)
|
|
84
|
+
- **Qué se está haciendo:** [backlog](docs/08-tareas/backlog.md)
|
|
85
|
+
- **Contribuir:** [CONTRIBUTING.md](CONTRIBUTING.md) · **Seguridad:** [SECURITY.md](SECURITY.md)
|
|
86
|
+
|
|
87
|
+
## Desarrollo
|
|
88
|
+
|
|
89
|
+
Requisitos: Node >= 22 y [pnpm](https://pnpm.io).
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
pnpm install # instala dependencias
|
|
93
|
+
pnpm verify # typecheck + lint + prettier + tests: antes de abrir un PR
|
|
94
|
+
pnpm build # genera dist/ (ESM + tipos)
|
|
95
|
+
pnpm test:package # build + prueba en Chromium de dist/ (requiere `pnpm exec playwright install chromium`)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Otros: `pnpm test`, `pnpm lint`, `pnpm api:check`, `pnpm package:lint`, `pnpm size`,
|
|
99
|
+
`pnpm test:a11y`, `pnpm test:audio`, `pnpm test:landing`.
|
|
100
|
+
|
|
101
|
+
## Licencia y atribución
|
|
102
|
+
|
|
103
|
+
[MIT](LICENSE). Usa el modelo MOSS-TTS-Nano de OpenMOSS Team (Fudan University, SII y MOSI),
|
|
104
|
+
publicado bajo Apache-2.0; los pesos no se redistribuyen en este paquete. `article-voice` no es un
|
|
105
|
+
proyecto oficial de OpenMOSS.
|
package/dist/index.d.ts
CHANGED
|
@@ -245,7 +245,9 @@ interface ExtractedArticle {
|
|
|
245
245
|
interface ArticleSource {
|
|
246
246
|
/** Candidatos descritos para `ArticleDetector`. */
|
|
247
247
|
candidates(explicitId?: string): ArticleCandidate[];
|
|
248
|
-
/**
|
|
248
|
+
/** Primer candidato que coincide con el selector CSS, si la fuente admite selectores. */
|
|
249
|
+
selectByCss?(selector: string): ArticleCandidate | undefined;
|
|
250
|
+
/** Bloques legibles del candidato (llamar tras obtenerlo de la fuente). */
|
|
249
251
|
extract(candidateId: string): ExtractedArticle | undefined;
|
|
250
252
|
}
|
|
251
253
|
|
|
@@ -306,8 +308,10 @@ declare class Article {
|
|
|
306
308
|
}
|
|
307
309
|
|
|
308
310
|
interface DetectArticleInput {
|
|
309
|
-
/** `for
|
|
311
|
+
/** ID explícito (`for`), con prioridad sobre `target`. */
|
|
310
312
|
readonly explicitId?: string;
|
|
313
|
+
/** Selector CSS explícito, usado cuando no se indica un ID. */
|
|
314
|
+
readonly target?: string;
|
|
311
315
|
readonly minWords?: MinWords;
|
|
312
316
|
/** Opción `lang`: manda sobre el idioma de la página (RN-10). */
|
|
313
317
|
readonly language?: string;
|
|
@@ -340,9 +344,9 @@ declare class HttpsUrl extends ValueObject<{
|
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
declare const SYSTEM_VOICE_LABEL = "voz del sistema";
|
|
343
|
-
type FallbackReason = 'no-server-url' | 'server-unreachable';
|
|
347
|
+
type FallbackReason = 'no-server-url' | 'server-unreachable' | 'server-synthesis-failed' | 'moss-browser-unavailable';
|
|
344
348
|
interface FallbackEvent {
|
|
345
|
-
readonly from: 'moss-server' | 'auto';
|
|
349
|
+
readonly from: 'moss-browser' | 'moss-server' | 'auto';
|
|
346
350
|
readonly to: 'web-speech';
|
|
347
351
|
readonly reason: FallbackReason;
|
|
348
352
|
readonly label: typeof SYSTEM_VOICE_LABEL;
|
|
@@ -350,6 +354,8 @@ interface FallbackEvent {
|
|
|
350
354
|
interface SelectEngineInput {
|
|
351
355
|
readonly engine?: EngineKind;
|
|
352
356
|
readonly serverUrl?: string | undefined;
|
|
357
|
+
/** Indica si la composición incluye el motor moss-browser. Por defecto, sí. */
|
|
358
|
+
readonly mossBrowserAvailable?: boolean;
|
|
353
359
|
/** Opción `fallback`; por defecto `web-speech`. */
|
|
354
360
|
readonly fallback?: 'web-speech' | 'none';
|
|
355
361
|
}
|
|
@@ -368,6 +374,7 @@ declare class SelectEngine {
|
|
|
368
374
|
private readonly onFallback;
|
|
369
375
|
constructor(capabilities: DeviceCapabilities, probe: ServerProbe, onFallback?: (event: FallbackEvent) => void);
|
|
370
376
|
execute(input?: SelectEngineInput, signal?: AbortSignal): Promise<SelectEngineOutput>;
|
|
377
|
+
private systemVoiceFallback;
|
|
371
378
|
private safeProbe;
|
|
372
379
|
private assertSystemVoice;
|
|
373
380
|
}
|
|
@@ -528,6 +535,8 @@ declare class ArticleVoiceElement extends BaseElement {
|
|
|
528
535
|
articleSource: ArticleSource;
|
|
529
536
|
createEngine: ((request: EngineRequest) => SpeechEngine) | undefined;
|
|
530
537
|
createAudioOutput: (() => AudioOutput) | undefined;
|
|
538
|
+
/** Disponibilidad del adaptador en la composición. */
|
|
539
|
+
protected readonly mossBrowserAvailable: boolean;
|
|
531
540
|
/** Resalta el segmento en lectura; sin él (o con `no-highlight`) no se resalta nada. */
|
|
532
541
|
highlighter: SegmentHighlighter | undefined;
|
|
533
542
|
/** D�nde se recuerdan velocidad y voz; por defecto localStorage (tolerante a fallos). */
|
|
@@ -547,6 +556,8 @@ declare class ArticleVoiceElement extends BaseElement {
|
|
|
547
556
|
}>;
|
|
548
557
|
get htmlFor(): string | null;
|
|
549
558
|
set htmlFor(v: string | null);
|
|
559
|
+
get target(): string | null;
|
|
560
|
+
set target(v: string | null);
|
|
550
561
|
get engine(): string;
|
|
551
562
|
set engine(v: string);
|
|
552
563
|
get fallback(): string;
|