@flamai/finesse 0.1.1 → 0.1.2
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/CHANGELOG.md +7 -1
- package/README.md +63 -14
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0.1.
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
- `output_format: "mulaw"` (raw G.711 µ-law) for telephony, with `sample_rate: 8000`, on
|
|
6
|
+
`speech` and realtime contexts. 8 kHz is now produced as asked; the README shows Twilio Media
|
|
7
|
+
Streams.
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
4
10
|
|
|
5
11
|
- Published on npm as `@flamai/finesse` (was private, installed from GitHub).
|
|
6
12
|
- Token clients (`accessToken`) retry only `429` and connections that never opened. The
|
package/README.md
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
</picture>
|
|
6
6
|
|
|
7
7
|
<p>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@flamai/finesse"><img alt="npm version" src="https://img.shields.io/npm/v/@flamai/finesse?style=flat&labelColor=14151A&color=2547F0"></a>
|
|
8
9
|
<img alt="Node 18+" src="https://img.shields.io/badge/node-18%2B-14151A?style=flat&labelColor=14151A&color=2547F0">
|
|
9
10
|
<img alt="Bun and Deno" src="https://img.shields.io/badge/also-Bun%20%C2%B7%20Deno-14151A?style=flat&labelColor=14151A&color=2547F0">
|
|
10
11
|
<img alt="TypeScript types included" src="https://img.shields.io/badge/types-included-14151A?style=flat&labelColor=14151A&color=2547F0">
|
|
11
12
|
<img alt="Status: beta" src="https://img.shields.io/badge/status-beta-14151A?style=flat&labelColor=14151A&color=63656A">
|
|
13
|
+
<a href="./LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-14151A?style=flat&labelColor=14151A&color=63656A"></a>
|
|
12
14
|
</p>
|
|
13
15
|
|
|
14
16
|
# Finesse TypeScript SDK
|
|
@@ -47,6 +49,11 @@ and stream it in realtime to voice agents, with a few lines of code.
|
|
|
47
49
|
- [Request IDs](#request-ids)
|
|
48
50
|
- [Advanced](#advanced)
|
|
49
51
|
- [Runtimes](#runtimes)
|
|
52
|
+
- [Requirements](#requirements)
|
|
53
|
+
- [Versioning](#versioning)
|
|
54
|
+
- [Getting help](#getting-help)
|
|
55
|
+
- [Security](#security)
|
|
56
|
+
- [Contributing](#contributing)
|
|
50
57
|
|
|
51
58
|
## Installation
|
|
52
59
|
|
|
@@ -56,8 +63,14 @@ Realtime in Node also needs the `ws` package:
|
|
|
56
63
|
npm install @flamai/finesse ws
|
|
57
64
|
# or
|
|
58
65
|
pnpm add @flamai/finesse ws
|
|
66
|
+
# or
|
|
67
|
+
yarn add @flamai/finesse ws
|
|
68
|
+
# or
|
|
69
|
+
bun add @flamai/finesse
|
|
59
70
|
```
|
|
60
71
|
|
|
72
|
+
`ws` is only needed for realtime in Node. Bun, Deno and browsers have a built-in `WebSocket`.
|
|
73
|
+
|
|
61
74
|
## Get an API key
|
|
62
75
|
|
|
63
76
|
1. Sign in to the [Finesse dashboard](https://finesse.flamapp.ai/dashboard).
|
|
@@ -181,7 +194,7 @@ const audio = await client.speech.create({
|
|
|
181
194
|
voice_id: voice.id,
|
|
182
195
|
text: "The quick brown fox jumps over the lazy dog.",
|
|
183
196
|
language: "en", // optional; defaults to the voice's language
|
|
184
|
-
output_format: "wav", // default; or raw PCM: "s16le", "s24le", "s32le", "f32le", "f64le"
|
|
197
|
+
output_format: "wav", // default; or raw PCM: "s16le", "s24le", "s32le", "f32le", "f64le", or "mulaw"
|
|
185
198
|
num_step: 32, // optional; 1-32, default 32; fewer steps is faster
|
|
186
199
|
});
|
|
187
200
|
|
|
@@ -331,11 +344,26 @@ outside `voice_ids` throws `PermissionDeniedError` with `code === "voice_not_all
|
|
|
331
344
|
| `s16le` | Raw PCM, 16-bit signed little-endian | `speech.stream`, realtime |
|
|
332
345
|
| `s24le`, `s32le` | Raw PCM, 24- or 32-bit signed | |
|
|
333
346
|
| `f32le`, `f64le` | Raw PCM, 32- or 64-bit float | |
|
|
347
|
+
| `mulaw` | Raw G.711 µ-law, for telephony | needs `sample_rate: 8000` |
|
|
334
348
|
| `opus` | Opus | realtime only |
|
|
335
349
|
|
|
336
|
-
All audio is mono. The engine's native rate is 24 kHz. You can ask for a higher `sample_rate`,
|
|
337
|
-
|
|
338
|
-
`audio.sampleRate`, `stream.sampleRate` or the `task_started` event.
|
|
350
|
+
All audio is mono. The engine's native rate is 24 kHz. You can ask for a higher `sample_rate`, or
|
|
351
|
+
for 8000 (telephony); other lower rates still come back at 24 kHz, so always read the actual rate
|
|
352
|
+
from `audio.sampleRate`, `stream.sampleRate` or the `task_started` event.
|
|
353
|
+
|
|
354
|
+
### Phone calls (Twilio)
|
|
355
|
+
|
|
356
|
+
Twilio Media Streams play 8 kHz µ-law. Ask for exactly that and send each chunk as the media
|
|
357
|
+
payload, base64-encoded; there is no WAV header to strip and nothing to resample:
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
const ctx = rt.context({ voice_id: voiceId, output_format: "mulaw", sample_rate: 8000 });
|
|
361
|
+
|
|
362
|
+
for await (const audio of ctx.audio()) {
|
|
363
|
+
const payload = Buffer.from(audio).toString("base64");
|
|
364
|
+
twilioWs.send(JSON.stringify({ event: "media", streamSid, media: { payload } }));
|
|
365
|
+
}
|
|
366
|
+
```
|
|
339
367
|
|
|
340
368
|
## Handling errors
|
|
341
369
|
|
|
@@ -486,22 +514,12 @@ const quick = client.withOptions({ timeout: 10_000, maxRetries: 0 });
|
|
|
486
514
|
await quick.voices.get(voiceId);
|
|
487
515
|
```
|
|
488
516
|
|
|
489
|
-
### Environments
|
|
490
|
-
|
|
491
|
-
The client talks to production by default. Point it elsewhere with `baseURL` or
|
|
492
|
-
`FINESSE_BASE_URL`:
|
|
493
|
-
|
|
494
|
-
```ts
|
|
495
|
-
const client = new Finesse({ baseURL: "https://finesse-proxy.example.com" });
|
|
496
|
-
```
|
|
497
|
-
|
|
498
517
|
### Configuration
|
|
499
518
|
|
|
500
519
|
| Option | Environment variable | Default |
|
|
501
520
|
| ------------------------- | -------------------- | ------------------------------------- |
|
|
502
521
|
| `apiKey` | `FINESSE_API_KEY` | required, unless `accessToken` |
|
|
503
522
|
| `accessToken` | | none (a short-lived `fin_tok_` token) |
|
|
504
|
-
| `baseURL` | `FINESSE_BASE_URL` | `https://fi.production.flamapis.com` |
|
|
505
523
|
| `timeout` | | 120 000 ms |
|
|
506
524
|
| `maxRetries` | | 2 |
|
|
507
525
|
| `defaultHeaders` | | none |
|
|
@@ -510,6 +528,8 @@ const client = new Finesse({ baseURL: "https://finesse-proxy.example.com" });
|
|
|
510
528
|
| `logLevel` | `FINESSE_LOG` | `"off"` |
|
|
511
529
|
| `logger` | | `console` |
|
|
512
530
|
|
|
531
|
+
An option passed to `new Finesse({...})` always wins over its environment variable.
|
|
532
|
+
|
|
513
533
|
### Custom fetch
|
|
514
534
|
|
|
515
535
|
Pass your own `fetch` for proxies, logging or tests:
|
|
@@ -542,11 +562,28 @@ Browsers can't keep an API key secret, so a client holding a key refuses to run
|
|
|
542
562
|
deprecated URL parameter, because browsers can't set WebSocket headers (as does Deno before
|
|
543
563
|
2.5), and logs a warning once.
|
|
544
564
|
|
|
565
|
+
## TypeScript types
|
|
566
|
+
|
|
567
|
+
Every request and response type is exported, so you can type your own code against the API:
|
|
568
|
+
|
|
569
|
+
```ts
|
|
570
|
+
import type { Voice } from "@flamai/finesse";
|
|
571
|
+
|
|
572
|
+
function label(voice: Voice) {
|
|
573
|
+
return `${voice.name} (${voice.id})`;
|
|
574
|
+
}
|
|
575
|
+
```
|
|
576
|
+
|
|
545
577
|
## Examples
|
|
546
578
|
|
|
547
579
|
Runnable scripts are in [`examples/`](./examples): [`speak.ts`](./examples/speak.ts) and
|
|
548
580
|
[`realtime.ts`](./examples/realtime.ts).
|
|
549
581
|
|
|
582
|
+
## Requirements
|
|
583
|
+
|
|
584
|
+
- Node 18 or later, Bun, Deno, or a modern browser (see [Runtimes](#runtimes)).
|
|
585
|
+
- TypeScript 4.7 or later, if you use TypeScript.
|
|
586
|
+
|
|
550
587
|
## Versioning
|
|
551
588
|
|
|
552
589
|
The SDK follows [semantic versioning](https://semver.org). Before 1.0, minor versions may
|
|
@@ -556,6 +593,18 @@ include breaking changes; they are listed in the [changelog](./CHANGELOG.md).
|
|
|
556
593
|
import { VERSION } from "@flamai/finesse";
|
|
557
594
|
```
|
|
558
595
|
|
|
596
|
+
## Getting help
|
|
597
|
+
|
|
598
|
+
- [Documentation](https://docs.finesse.flamapp.ai) for guides and the API reference.
|
|
599
|
+
- [GitHub issues](https://github.com/homingos/finesse-node/issues) for bugs and feature requests
|
|
600
|
+
in this SDK. Include the `requestId` from the error (see [Request IDs](#request-ids)) when
|
|
601
|
+
a request failed.
|
|
602
|
+
|
|
603
|
+
## Security
|
|
604
|
+
|
|
605
|
+
Please don't report security problems in a public issue. See [SECURITY.md](./SECURITY.md) for
|
|
606
|
+
how to report one privately.
|
|
607
|
+
|
|
559
608
|
## Contributing
|
|
560
609
|
|
|
561
610
|
```sh
|