@happyvertical/speech 0.78.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/AGENT.md +51 -0
- package/LICENSE +7 -0
- package/README.md +85 -0
- package/dist/adapters/openai-compatible.d.ts +11 -0
- package/dist/adapters/openai-compatible.d.ts.map +1 -0
- package/dist/adapters/qwen3.d.ts +11 -0
- package/dist/adapters/qwen3.d.ts.map +1 -0
- package/dist/adapters/studio-server.d.ts +16 -0
- package/dist/adapters/studio-server.d.ts.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +694 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/errors.d.ts +21 -0
- package/dist/shared/errors.d.ts.map +1 -0
- package/dist/shared/factory.d.ts +22 -0
- package/dist/shared/factory.d.ts.map +1 -0
- package/dist/shared/http.d.ts +31 -0
- package/dist/shared/http.d.ts.map +1 -0
- package/dist/shared/types.d.ts +143 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/metadata.json +31 -0
- package/package.json +58 -0
package/AGENT.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @happyvertical/speech
|
|
2
|
+
|
|
3
|
+
<!-- BEGIN AGENT:GENERATED -->
|
|
4
|
+
## Purpose
|
|
5
|
+
Speech provider abstraction for STT and TTS backends
|
|
6
|
+
|
|
7
|
+
## Package Map
|
|
8
|
+
- Package: `@happyvertical/speech`
|
|
9
|
+
- Hierarchy path: `@happyvertical/sdk > packages > speech`
|
|
10
|
+
- Workspace position: `26 of 31` local packages
|
|
11
|
+
- Internal dependencies: none
|
|
12
|
+
- Internal dependents: none
|
|
13
|
+
- Knowledge graph files: `AGENT.md`, `metadata.json`, `ecosystem-manifest.json`
|
|
14
|
+
|
|
15
|
+
## Build & Test
|
|
16
|
+
```bash
|
|
17
|
+
pnpm --filter @happyvertical/speech build
|
|
18
|
+
pnpm --filter @happyvertical/speech test
|
|
19
|
+
pnpm --filter @happyvertical/speech typecheck
|
|
20
|
+
pnpm --filter @happyvertical/speech clean
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Agent Correction Loops
|
|
24
|
+
- If Vite or TypeScript reports missing packages, run `pnpm install` at the repo root and rerun `pnpm --filter @happyvertical/speech build`.
|
|
25
|
+
- If tests or exports fail after API, type, or bundle changes, run `pnpm --filter @happyvertical/speech clean` followed by `pnpm --filter @happyvertical/speech build` and `pnpm --filter @happyvertical/speech test`.
|
|
26
|
+
- If failures span multiple packages or Turborepo ordering looks wrong, run `pnpm build` and `pnpm typecheck` from the repo root before retrying package-scoped commands.
|
|
27
|
+
|
|
28
|
+
## Ecosystem Relationships
|
|
29
|
+
- Provides: Speech provider abstraction for STT and TTS backends
|
|
30
|
+
- Implements: Studio Server STT, Studio Server TTS, Qwen3 TTS, OpenAI-compatible TTS
|
|
31
|
+
- Requires: none
|
|
32
|
+
- Stability: experimental (Marked as preview or experimental in package guidance.)
|
|
33
|
+
<!-- END AGENT:GENERATED -->
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## SDK Pattern
|
|
37
|
+
|
|
38
|
+
Use factory functions as the public surface:
|
|
39
|
+
|
|
40
|
+
- `getSpeech(config)` returns a service with optional STT and TTS providers.
|
|
41
|
+
- `getTranscriber(config)` creates an STT provider.
|
|
42
|
+
- `getSpeechSynthesizer(config)` creates a TTS provider.
|
|
43
|
+
|
|
44
|
+
Adapter constructors are internal implementation details. Keep new backends behind the `type` option and the factory switch.
|
|
45
|
+
|
|
46
|
+
## Adapters
|
|
47
|
+
|
|
48
|
+
- Studio Server STT (`type: 'studio-server'`) posts multipart audio to `/v1/transcribe`.
|
|
49
|
+
- Studio Server TTS (`type: 'studio-server'`) posts multipart form data to `/v1/tts/synthesize`.
|
|
50
|
+
- Qwen3 TTS (`type: 'qwen3-tts'`) posts multipart form data to `/v1/audio/speech`.
|
|
51
|
+
- OpenAI-compatible TTS (`type: 'openai-compatible'`) posts OpenAI-shaped JSON to `/v1/audio/speech`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @happyvertical/speech
|
|
2
|
+
|
|
3
|
+
Speech provider abstraction for HappyVertical STT and TTS backends.
|
|
4
|
+
|
|
5
|
+
This package owns runtime speech backend contracts. It is intentionally separate from SMRT model packages such as `@happyvertical/smrt-voice`, which persist voice profiles, samples, and generated outputs.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @happyvertical/speech
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { getSpeech } from '@happyvertical/speech';
|
|
17
|
+
|
|
18
|
+
const speech = await getSpeech({
|
|
19
|
+
transcriber: {
|
|
20
|
+
type: 'studio-server',
|
|
21
|
+
baseUrl: 'http://studio-server.studio-server.svc.cluster.local',
|
|
22
|
+
},
|
|
23
|
+
synthesizer: {
|
|
24
|
+
type: 'qwen3-tts',
|
|
25
|
+
baseUrl: 'http://qwen3-tts.qwen3-tts.svc.cluster.local',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const transcript = await speech.transcribe({
|
|
30
|
+
audio: {
|
|
31
|
+
data: audioBytes,
|
|
32
|
+
contentType: 'audio/wav',
|
|
33
|
+
filename: 'utterance.wav',
|
|
34
|
+
},
|
|
35
|
+
language: 'en',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const spoken = await speech.synthesize({
|
|
39
|
+
text: transcript.text,
|
|
40
|
+
outputFormat: 'mp3',
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Adapters
|
|
45
|
+
|
|
46
|
+
| Provider | Type | Method | Path | Encoding |
|
|
47
|
+
| --- | --- | --- | --- | --- |
|
|
48
|
+
| Studio Server STT | `studio-server` | `POST` | `/v1/transcribe` | Multipart (`audio`) |
|
|
49
|
+
| Studio Server TTS | `studio-server` | `POST` | `/v1/tts/synthesize` | Multipart |
|
|
50
|
+
| Qwen3 TTS | `qwen3-tts` | `POST` | `/v1/audio/speech` | Multipart |
|
|
51
|
+
| OpenAI-compatible TTS | `openai-compatible` | `POST` | `/v1/audio/speech` | JSON |
|
|
52
|
+
|
|
53
|
+
Studio Server and Qwen3 accept pre-extracted provider voice prompts through `SpeechVoice.prompt`; the adapters forward these as the multipart `voice_prompt` field.
|
|
54
|
+
|
|
55
|
+
## Environment Configuration
|
|
56
|
+
|
|
57
|
+
SDK-style names are preferred:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
HAVE_SPEECH_STT_TYPE=studio-server
|
|
61
|
+
HAVE_SPEECH_STT_BASE_URL=http://studio-server.studio-server.svc.cluster.local
|
|
62
|
+
HAVE_SPEECH_TTS_TYPE=qwen3-tts
|
|
63
|
+
HAVE_SPEECH_TTS_BASE_URL=http://qwen3-tts.qwen3-tts.svc.cluster.local
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
STT defaults to `studio-server` when only a base URL is present. TTS requires an explicit type because multiple TTS wire protocols are supported.
|
|
67
|
+
|
|
68
|
+
For gateway compatibility, the package also accepts:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
STT_ADAPTER=studio-server
|
|
72
|
+
STT_BASE_URL=http://studio-server.studio-server.svc.cluster.local
|
|
73
|
+
TTS_ADAPTER=qwen3-tts
|
|
74
|
+
TTS_BASE_URL=http://qwen3-tts.qwen3-tts.svc.cluster.local
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Optional overrides include `STT_PATH`, `TTS_PATH`, `STT_API_KEY`, `TTS_API_KEY`, `SPEECH_API_KEY`, `STT_TIMEOUT_MS`, and `TTS_TIMEOUT_MS`.
|
|
78
|
+
|
|
79
|
+
## Testing
|
|
80
|
+
|
|
81
|
+
Default tests use tiny in-process HTTP fixture services that mirror the Studio Server, Qwen3, and OpenAI-compatible request shapes. They validate field names, encodings, and response normalization without downloading production-scale models.
|
|
82
|
+
|
|
83
|
+
Docker or Testcontainers integration suites should run the fixture services or Studio Server with mock backends. Model-backed tests must remain opt-in, for example behind `HV_SPEECH_MODEL_TESTS=1`, so the normal SDK suite never downloads model weights.
|
|
84
|
+
|
|
85
|
+
On Apple Silicon, run model-backed Qwen tests with a host-native Metal/MLX runtime or against a remote cluster service; Docker contract tests should continue using mock backends because Linux containers do not expose the host Metal runtime.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpSpeechAdapter } from '../shared/http.js';
|
|
2
|
+
import { OpenAICompatibleSpeechSynthesizerOptions, SpeechSynthesizer, SynthesisRequest, SynthesizedSpeech } from '../shared/types.js';
|
|
3
|
+
export declare class OpenAICompatibleSpeechSynthesizer extends HttpSpeechAdapter implements SpeechSynthesizer {
|
|
4
|
+
readonly type: "openai-compatible";
|
|
5
|
+
private readonly speechPath;
|
|
6
|
+
private readonly defaultModel;
|
|
7
|
+
private readonly defaultVoice;
|
|
8
|
+
constructor(options: OpenAICompatibleSpeechSynthesizerOptions);
|
|
9
|
+
synthesize(request: SynthesisRequest): Promise<SynthesizedSpeech>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=openai-compatible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-compatible.d.ts","sourceRoot":"","sources":["../../src/adapters/openai-compatible.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,wCAAwC,EACxC,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,iCACX,SAAQ,iBACR,YAAW,iBAAiB;IAE5B,QAAQ,CAAC,IAAI,EAAG,mBAAmB,CAAU;IAE7C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAE1B,OAAO,EAAE,wCAAwC;IAOvD,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA8BxE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HttpSpeechAdapter } from '../shared/http.js';
|
|
2
|
+
import { Qwen3SpeechSynthesizerOptions, SpeechSynthesizer, SynthesisRequest, SynthesizedSpeech } from '../shared/types.js';
|
|
3
|
+
export declare class Qwen3SpeechSynthesizer extends HttpSpeechAdapter implements SpeechSynthesizer {
|
|
4
|
+
readonly type: "qwen3-tts";
|
|
5
|
+
private readonly speechPath;
|
|
6
|
+
private readonly defaultModel;
|
|
7
|
+
private readonly defaultVoice?;
|
|
8
|
+
constructor(options: Qwen3SpeechSynthesizerOptions);
|
|
9
|
+
synthesize(request: SynthesisRequest): Promise<SynthesizedSpeech>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=qwen3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qwen3.d.ts","sourceRoot":"","sources":["../../src/adapters/qwen3.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,6BAA6B,EAC7B,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,sBACX,SAAQ,iBACR,YAAW,iBAAiB;IAE5B,QAAQ,CAAC,IAAI,EAAG,WAAW,CAAU;IAErC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAS;gBAE3B,OAAO,EAAE,6BAA6B;IAO5C,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAkBxE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HttpSpeechAdapter } from '../shared/http.js';
|
|
2
|
+
import { SpeechSynthesizer, StudioServerSpeechSynthesizerOptions, StudioServerTranscriberOptions, SynthesisRequest, SynthesizedSpeech, Transcriber, TranscriptionRequest, TranscriptResult } from '../shared/types.js';
|
|
3
|
+
export declare class StudioServerTranscriber extends HttpSpeechAdapter implements Transcriber {
|
|
4
|
+
readonly type: "studio-server";
|
|
5
|
+
private readonly transcribePath;
|
|
6
|
+
constructor(options: StudioServerTranscriberOptions);
|
|
7
|
+
transcribe(request: TranscriptionRequest): Promise<TranscriptResult>;
|
|
8
|
+
}
|
|
9
|
+
export declare class StudioServerSpeechSynthesizer extends HttpSpeechAdapter implements SpeechSynthesizer {
|
|
10
|
+
readonly type: "studio-server";
|
|
11
|
+
private readonly synthesizePath;
|
|
12
|
+
private readonly defaultVoice?;
|
|
13
|
+
constructor(options: StudioServerSpeechSynthesizerOptions);
|
|
14
|
+
synthesize(request: SynthesisRequest): Promise<SynthesizedSpeech>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=studio-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-server.d.ts","sourceRoot":"","sources":["../../src/adapters/studio-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iBAAiB,EAGlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,iBAAiB,EACjB,oCAAoC,EACpC,8BAA8B,EAC9B,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,uBACX,SAAQ,iBACR,YAAW,WAAW;IAEtB,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,OAAO,EAAE,8BAA8B;IAK7C,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAe3E;AAED,qBAAa,6BACX,SAAQ,iBACR,YAAW,iBAAiB;IAE5B,QAAQ,CAAC,IAAI,EAAG,eAAe,CAAU;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAS;gBAE3B,OAAO,EAAE,oCAAoC;IAMnD,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAaxE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @happyvertical/speech
|
|
3
|
+
*
|
|
4
|
+
* Speech provider abstraction for STT and TTS backends.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { getSpeech } from '@happyvertical/speech';
|
|
9
|
+
*
|
|
10
|
+
* const speech = await getSpeech({
|
|
11
|
+
* transcriber: {
|
|
12
|
+
* type: 'studio-server',
|
|
13
|
+
* baseUrl: 'http://studio-server.studio-server.svc.cluster.local',
|
|
14
|
+
* },
|
|
15
|
+
* synthesizer: {
|
|
16
|
+
* type: 'qwen3-tts',
|
|
17
|
+
* baseUrl: 'http://qwen3-tts.qwen3-tts.svc.cluster.local',
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
export * from './shared/errors.js';
|
|
25
|
+
export { getAvailableSpeechAdapters, getSpeech, getSpeechSynthesizer, getTranscriber, type SpeechFactoryContext, } from './shared/factory.js';
|
|
26
|
+
export type { AudioBytes, AudioInput, GetSpeechOptions, GetSpeechSynthesizerOptions, GetTranscriberOptions, OpenAICompatibleSpeechSynthesizerOptions, Qwen3SpeechSynthesizerOptions, Speech, SpeechAdapterAvailability, SpeechAdapterType, SpeechFetch, SpeechSynthesizer, SpeechSynthesizerType, SpeechVoice, SpeechVoiceInput, StudioServerSpeechSynthesizerOptions, StudioServerTranscriberOptions, SynthesisRequest, SynthesizedSpeech, Transcriber, TranscriberType, TranscriptionRequest, TranscriptResult, TranscriptSegment, WordTiming, } from './shared/types.js';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,cAAc,oBAAoB,CAAC;AACnC,OAAO,EACL,0BAA0B,EAC1B,SAAS,EACT,oBAAoB,EACpB,cAAc,EACd,KAAK,oBAAoB,GAC1B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,2BAA2B,EAC3B,qBAAqB,EACrB,wCAAwC,EACxC,6BAA6B,EAC7B,MAAM,EACN,yBAAyB,EACzB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,qBAAqB,EACrB,WAAW,EACX,gBAAgB,EAChB,oCAAoC,EACpC,8BAA8B,EAC9B,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,mBAAmB,CAAC"}
|