@effect-uai/inworld 0.17.0 → 0.18.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/dist/InworldRealtimeSynthesizer.d.mts +1 -1
- package/dist/InworldRealtimeSynthesizer.mjs +2 -2
- package/dist/InworldRealtimeSynthesizer.mjs.map +1 -1
- package/dist/InworldRealtimeTranscriber.d.mts +1 -1
- package/dist/InworldRealtimeTranscriber.mjs +2 -2
- package/dist/InworldRealtimeTranscriber.mjs.map +1 -1
- package/dist/InworldSynthesizer.d.mts +1 -1
- package/dist/InworldSynthesizer.mjs +2 -2
- package/dist/InworldSynthesizer.mjs.map +1 -1
- package/dist/InworldTranscriber.d.mts +1 -1
- package/dist/InworldTranscriber.d.mts.map +1 -1
- package/dist/InworldTranscriber.mjs +5 -4
- package/dist/InworldTranscriber.mjs.map +1 -1
- package/dist/codec-BU4azW_k.d.mts.map +1 -1
- package/dist/codec.mjs +4 -3
- package/dist/codec.mjs.map +1 -1
- package/dist/dist-Cu2gIMHV.mjs +17453 -0
- package/dist/dist-Cu2gIMHV.mjs.map +1 -0
- package/dist/dist-DHer1cql.mjs +1533 -0
- package/dist/dist-DHer1cql.mjs.map +1 -0
- package/dist/realtimeStt.d.mts +6 -0
- package/dist/realtimeStt.d.mts.map +1 -1
- package/dist/realtimeStt.mjs +18 -19
- package/dist/realtimeStt.mjs.map +1 -1
- package/dist/realtimeStt.test.d.mts +1 -0
- package/dist/realtimeStt.test.mjs +83 -0
- package/dist/realtimeStt.test.mjs.map +1 -0
- package/dist/realtimeTts.d.mts +6 -0
- package/dist/realtimeTts.d.mts.map +1 -1
- package/dist/realtimeTts.mjs +18 -17
- package/dist/realtimeTts.mjs.map +1 -1
- package/dist/realtimeTts.test.d.mts +1 -0
- package/dist/realtimeTts.test.mjs +70 -0
- package/dist/realtimeTts.test.mjs.map +1 -0
- package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-EAsCxrDo.mjs} +2 -1
- package/dist/wsAuth.d.mts +1 -1
- package/dist/wsAuth.mjs.map +1 -1
- package/package.json +4 -4
- package/src/InworldRealtimeSynthesizer.ts +1 -1
- package/src/InworldRealtimeTranscriber.ts +1 -1
- package/src/InworldSynthesizer.ts +1 -1
- package/src/InworldTranscriber.ts +4 -3
- package/src/codec.ts +3 -2
- package/src/realtimeStt.test.ts +82 -0
- package/src/realtimeStt.ts +46 -36
- package/src/realtimeTts.test.ts +74 -0
- package/src/realtimeTts.ts +52 -36
- package/src/wsAuth.ts +1 -1
package/src/realtimeTts.ts
CHANGED
|
@@ -19,17 +19,26 @@
|
|
|
19
19
|
* Multi-context (`contextId`) is not surfaced here — one logical
|
|
20
20
|
* utterance per call.
|
|
21
21
|
*/
|
|
22
|
-
import {
|
|
23
|
-
import * as Socket from "effect/
|
|
22
|
+
import { Effect, Option, Predicate, Redacted, Schema, Stream } from "effect"
|
|
23
|
+
import * as Socket from "effect/socket/Socket"
|
|
24
24
|
import * as AiError from "@effect-uai/core/AiError"
|
|
25
25
|
import type { AudioChunk, AudioFormat } from "@effect-uai/core/Audio"
|
|
26
26
|
import * as JSONL from "@effect-uai/core/JSONL"
|
|
27
27
|
import type { CustomPronunciation } from "@effect-uai/core/SpeechSynthesizer"
|
|
28
|
+
import * as WebSocketSession from "@effect-uai/core/WebSocketSession"
|
|
28
29
|
import { audioConfigFor, decodeAudioContent, defaultFormat } from "./codec.js"
|
|
29
30
|
import type { InworldDeliveryMode, InworldTtsModel, InworldVoiceId } from "./models.js"
|
|
30
31
|
import { authedWsConstructor } from "./wsAuth.js"
|
|
31
32
|
|
|
32
|
-
export type Config = {
|
|
33
|
+
export type Config = {
|
|
34
|
+
readonly apiKey: Redacted.Redacted
|
|
35
|
+
readonly baseUrl?: string
|
|
36
|
+
/**
|
|
37
|
+
* Build the socket yourself, for a proxy or an in-memory transport. The
|
|
38
|
+
* default attaches the Basic auth header through the `ws` package.
|
|
39
|
+
*/
|
|
40
|
+
readonly webSocket?: Socket.WebSocketConstructor["Service"]
|
|
41
|
+
}
|
|
33
42
|
|
|
34
43
|
/**
|
|
35
44
|
* Incremental-text-in request. Mirrors the sync request minus `text` (which
|
|
@@ -110,21 +119,25 @@ const ServerFrame = Schema.Struct({
|
|
|
110
119
|
})
|
|
111
120
|
const decodeServerFrame = Schema.decodeUnknownEffect(ServerFrame)
|
|
112
121
|
|
|
113
|
-
|
|
122
|
+
/** One raw text frame to at most one audio chunk; error frames are logged, not raised. */
|
|
123
|
+
const frameToChunk = (raw: string): Effect.Effect<AudioChunk | undefined> =>
|
|
114
124
|
Effect.gen(function* () {
|
|
115
125
|
const json = yield* JSONL.parseSafe(raw)
|
|
116
|
-
if (json === undefined) return
|
|
126
|
+
if (json === undefined) return undefined
|
|
117
127
|
const decoded = yield* decodeServerFrame(json).pipe(Effect.option)
|
|
118
|
-
if (decoded
|
|
128
|
+
if (Option.isNone(decoded)) return undefined
|
|
119
129
|
const frame = decoded.value
|
|
120
130
|
if (frame.error !== undefined) {
|
|
121
131
|
yield* Effect.logWarning("[inworld-tts] server error frame", { error: frame.error })
|
|
122
|
-
return
|
|
132
|
+
return undefined
|
|
123
133
|
}
|
|
124
134
|
const audio = frame.result?.audioChunk?.audioContent
|
|
125
|
-
if (audio === undefined || audio === "") return
|
|
135
|
+
if (audio === undefined || audio === "") return undefined
|
|
126
136
|
const bytes = yield* decodeAudioContent(audio).pipe(Effect.option)
|
|
127
|
-
|
|
137
|
+
return Option.match(bytes, {
|
|
138
|
+
onNone: () => undefined,
|
|
139
|
+
onSome: (b): AudioChunk => ({ bytes: b }),
|
|
140
|
+
})
|
|
128
141
|
})
|
|
129
142
|
|
|
130
143
|
// ---------------------------------------------------------------------------
|
|
@@ -153,32 +166,35 @@ export const streamSynthesis =
|
|
|
153
166
|
)
|
|
154
167
|
}
|
|
155
168
|
const create = yield* createFrame(request)
|
|
156
|
-
const socket = yield* Socket.makeWebSocket(buildWsUrl(cfg)
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const write = yield* socket.writer
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
169
|
+
const socket = yield* Socket.makeWebSocket(buildWsUrl(cfg)).pipe(
|
|
170
|
+
Effect.provideService(
|
|
171
|
+
Socket.WebSocketConstructor,
|
|
172
|
+
cfg.webSocket ?? authedWsConstructor(cfg.apiKey),
|
|
173
|
+
),
|
|
174
|
+
)
|
|
175
|
+
const { write } = yield* socket.writer
|
|
176
|
+
const asAiError = WebSocketSession.toAiError("inworld")
|
|
177
|
+
|
|
178
|
+
const chunks = Stream.fromPull(Socket.readerString(socket)).pipe(
|
|
179
|
+
Stream.scoped,
|
|
180
|
+
Stream.catchIf(WebSocketSession.isCleanClose, () => Stream.empty),
|
|
181
|
+
Stream.mapError(asAiError),
|
|
182
|
+
Stream.mapEffect(frameToChunk),
|
|
183
|
+
Stream.filter(Predicate.isNotUndefined),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
const outgoing = Stream.concat(
|
|
187
|
+
Stream.make(create),
|
|
188
|
+
Stream.concat(
|
|
189
|
+
textIn.pipe(
|
|
190
|
+
Stream.filter((text) => text.length > 0),
|
|
191
|
+
Stream.map(sendTextFrame),
|
|
192
|
+
),
|
|
193
|
+
Stream.make(closeContextFrame),
|
|
194
|
+
),
|
|
195
|
+
).pipe(Stream.mapEffect((frame) => Effect.mapError(write(frame), asAiError)))
|
|
196
|
+
|
|
197
|
+
// The server drains remaining audio after `close_context`, then closes.
|
|
198
|
+
return Stream.merge(chunks, Stream.drain(outgoing), { haltStrategy: "left" })
|
|
183
199
|
}),
|
|
184
200
|
)
|
package/src/wsAuth.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* we use the `ws` peer dep (Node/Bun only).
|
|
10
10
|
*/
|
|
11
11
|
import { Redacted } from "effect"
|
|
12
|
-
import type * as Socket from "effect/
|
|
12
|
+
import type * as Socket from "effect/socket/Socket"
|
|
13
13
|
import { WebSocket as WSWebSocket } from "ws"
|
|
14
14
|
import { authHeader } from "./codec.js"
|
|
15
15
|
|