@simonpeacocks/peacockery-voice-client 0.1.4 → 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/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type PeacockeryVoiceClientOptions } from "./auth.js";
2
2
  import type { paths } from "./schema.js";
3
3
  export { type PeacockeryVoiceClientOptions, type PeacockeryVoiceDpopBindingProofInput, type PeacockeryVoiceDpopBindingProofProvider, type PeacockeryVoiceDpopProofInput, type PeacockeryVoiceDpopProofProvider, type PeacockeryVoiceEnvironment, peacockeryVoiceBaseUrls, } from "./auth.js";
4
- export { createPeacockeryVoiceRealtimeRequest, type PeacockeryVoiceRealtimeAudioReceivedEvent, type PeacockeryVoiceRealtimeEvent, type PeacockeryVoiceRealtimeOptions, type PeacockeryVoiceRealtimePongEvent, type PeacockeryVoiceRealtimeRequest, type PeacockeryVoiceRealtimeSessionStartedEvent, type PeacockeryVoiceRealtimeTranscriptEvent, parsePeacockeryVoiceRealtimeEvent, } from "./realtime.js";
4
+ export { createPeacockeryVoiceRealtimeRequest, type PeacockeryVoiceRealtimeAudioReceivedEvent, type PeacockeryVoiceRealtimeEvent, type PeacockeryVoiceRealtimeOptions, type PeacockeryVoiceRealtimePongEvent, type PeacockeryVoiceRealtimeRequest, type PeacockeryVoiceRealtimeSessionStartedEvent, type PeacockeryVoiceRealtimeTranscriptEvent, type PeacockeryVoiceRealtimeTurnEvent, parsePeacockeryVoiceRealtimeEvent, } from "./realtime.js";
5
5
  export type { components, operations, paths } from "./schema.js";
6
6
  export declare const createPeacockeryVoiceClient: (options: PeacockeryVoiceClientOptions) => import("openapi-fetch").Client<paths, `${string}/${string}`>;
7
7
  export type PeacockeryVoiceClient = ReturnType<typeof createPeacockeryVoiceClient>;
@@ -1,19 +1,43 @@
1
1
  import { type PeacockeryVoiceClientOptions } from "./auth.js";
2
2
  import type { components } from "./schema.js";
3
3
  type RealtimeTerminalEvent = components["schemas"]["RealtimeSessionResult"];
4
- type TranscriptionArtifact = components["schemas"]["TranscriptionArtifact"];
5
- type TranscriptSegment = TranscriptionArtifact["content"]["segments"]["items"][number];
6
- type TranscriptSpeakerTurn = TranscriptionArtifact["content"]["speaker_turns"]["items"][number];
7
- type TranscriptWord = TranscriptionArtifact["content"]["words"]["items"][number];
4
+ interface TranscriptSegment {
5
+ endSeconds: number | null;
6
+ scores?: {
7
+ confidence?: number;
8
+ logProbability?: number;
9
+ probability?: number;
10
+ score?: number;
11
+ speakerConfidence?: number;
12
+ };
13
+ speaker?: string | number;
14
+ startSeconds: number | null;
15
+ text: string;
16
+ }
17
+ type TranscriptSpeakerTurn = Omit<TranscriptSegment, "scores">;
18
+ type TranscriptWord = TranscriptSegment & {
19
+ startSeconds: number;
20
+ endSeconds: number;
21
+ };
8
22
  export interface PeacockeryVoiceRealtimeOptions extends PeacockeryVoiceClientOptions {
9
23
  channels?: number;
24
+ contextBias?: string[];
25
+ diarize?: boolean;
10
26
  encoding?: string;
11
27
  endpointing?: string;
12
28
  interimResults?: boolean;
13
29
  language?: string;
14
30
  model: string;
15
31
  sampleRate?: number;
32
+ speakerReferences?: Record<string, string>;
16
33
  targetStreamingDelayMs?: number;
34
+ turnDetection?: {
35
+ start_threshold?: number;
36
+ eager_end_threshold?: number;
37
+ end_threshold?: number;
38
+ min_silence_ms?: number;
39
+ end_timeout_ms?: number;
40
+ };
17
41
  utteranceEndMs?: number;
18
42
  vadEvents?: boolean;
19
43
  }
@@ -51,7 +75,12 @@ export interface PeacockeryVoiceRealtimePongEvent {
51
75
  session_id: string;
52
76
  type: "pong";
53
77
  }
54
- export type PeacockeryVoiceRealtimeEvent = PeacockeryVoiceRealtimeAudioReceivedEvent | PeacockeryVoiceRealtimePongEvent | PeacockeryVoiceRealtimeSessionStartedEvent | PeacockeryVoiceRealtimeTranscriptEvent | RealtimeTerminalEvent;
78
+ export interface PeacockeryVoiceRealtimeTurnEvent extends RealtimeEventBase {
79
+ end_reason?: "threshold" | "timeout";
80
+ time_seconds: number;
81
+ type: "turn.start" | "turn.eager_end" | "turn.resume" | "turn.end";
82
+ }
83
+ export type PeacockeryVoiceRealtimeEvent = PeacockeryVoiceRealtimeTurnEvent | PeacockeryVoiceRealtimeAudioReceivedEvent | PeacockeryVoiceRealtimePongEvent | PeacockeryVoiceRealtimeSessionStartedEvent | PeacockeryVoiceRealtimeTranscriptEvent | RealtimeTerminalEvent;
55
84
  export declare const createPeacockeryVoiceRealtimeRequest: (options: PeacockeryVoiceRealtimeOptions) => Promise<PeacockeryVoiceRealtimeRequest>;
56
85
  export declare const parsePeacockeryVoiceRealtimeEvent: (value: string | unknown) => PeacockeryVoiceRealtimeEvent;
57
86
  export {};
package/dist/realtime.js CHANGED
@@ -4,13 +4,20 @@ const realtimeHttpUrl = (options) => {
4
4
  const url = new URL("/v1/realtime", options.baseUrl ?? peacockeryVoiceBaseUrls[environment]);
5
5
  const query = {
6
6
  channels: options.channels,
7
+ diarize: options.diarize,
7
8
  encoding: options.encoding,
8
9
  endpointing: options.endpointing,
9
10
  interim_results: options.interimResults,
10
11
  language: options.language,
11
12
  model: options.model,
12
13
  sample_rate: options.sampleRate,
14
+ speaker_references: options.speakerReferences
15
+ ? JSON.stringify(options.speakerReferences)
16
+ : undefined,
13
17
  target_streaming_delay_ms: options.targetStreamingDelayMs,
18
+ turn_detection: options.turnDetection
19
+ ? JSON.stringify(options.turnDetection)
20
+ : undefined,
14
21
  utterance_end_ms: options.utteranceEndMs,
15
22
  vad_events: options.vadEvents,
16
23
  };
@@ -19,6 +26,9 @@ const realtimeHttpUrl = (options) => {
19
26
  url.searchParams.set(name, String(value));
20
27
  }
21
28
  }
29
+ for (const term of options.contextBias ?? []) {
30
+ url.searchParams.append("context_bias", term);
31
+ }
22
32
  return url;
23
33
  };
24
34
  const headersRecord = (headers) => {
@@ -79,6 +89,12 @@ export const createPeacockeryVoiceRealtimeRequest = async (options) => {
79
89
  return { headers: headersRecord(headers), url: url.href };
80
90
  };
81
91
  const isRecord = (value) => typeof value === "object" && value !== null;
92
+ const isTurnEvent = (value) => typeof value.time_seconds === "number" &&
93
+ Number.isFinite(value.time_seconds) &&
94
+ value.time_seconds >= 0 &&
95
+ (value.end_reason === undefined ||
96
+ value.end_reason === "threshold" ||
97
+ value.end_reason === "timeout");
82
98
  const isRealtimeEvent = (value) => {
83
99
  if (!isRecord(value) || typeof value.type !== "string") {
84
100
  return false;
@@ -99,6 +115,9 @@ const isRealtimeEvent = (value) => {
99
115
  if (!hasProtocolBase) {
100
116
  return false;
101
117
  }
118
+ if (["turn.start", "turn.eager_end", "turn.resume", "turn.end"].includes(value.type)) {
119
+ return isTurnEvent(value);
120
+ }
102
121
  if (value.type === "session.started") {
103
122
  return ((typeof value.language === "string" || value.language === null) &&
104
123
  typeof value.model === "string");
package/dist/schema.d.ts CHANGED
@@ -1402,6 +1402,7 @@ export interface paths {
1402
1402
  query?: {
1403
1403
  audio_format?: string;
1404
1404
  channels?: number;
1405
+ context_bias?: string;
1405
1406
  detect_entities?: "true" | "false";
1406
1407
  diarize?: "true" | "false";
1407
1408
  diarize_model?: "latest" | "v1";
@@ -1425,8 +1426,12 @@ export interface paths {
1425
1426
  sample_rate?: number;
1426
1427
  search?: string;
1427
1428
  smart_format?: "true" | "false";
1429
+ /** @description JSON object mapping speaker names to completed upload input_key values */
1430
+ speaker_references?: string;
1428
1431
  tag?: string;
1429
1432
  target_streaming_delay_ms?: number;
1433
+ /** @description JSON turn-detection configuration; {} uses provider defaults */
1434
+ turn_detection?: string;
1430
1435
  utterance_end_ms?: number;
1431
1436
  vad_events?: "true" | "false";
1432
1437
  version?: string;
@@ -2114,7 +2119,7 @@ export interface components {
2114
2119
  /** @enum {string|null} */
2115
2120
  source: "derived" | "provider" | null;
2116
2121
  items: {
2117
- end_seconds: number;
2122
+ end_seconds: number | null;
2118
2123
  scores: {
2119
2124
  confidence: number | null;
2120
2125
  log_probability: number | null;
@@ -2123,7 +2128,7 @@ export interface components {
2123
2128
  speaker_confidence: number | null;
2124
2129
  } | null;
2125
2130
  speaker: string | number | null;
2126
- start_seconds: number;
2131
+ start_seconds: number | null;
2127
2132
  text: string;
2128
2133
  }[];
2129
2134
  };
@@ -2133,9 +2138,9 @@ export interface components {
2133
2138
  /** @enum {string|null} */
2134
2139
  source: "derived" | "provider" | null;
2135
2140
  items: {
2136
- end_seconds: number;
2141
+ end_seconds: number | null;
2137
2142
  speaker: string | number | null;
2138
- start_seconds: number;
2143
+ start_seconds: number | null;
2139
2144
  text: string;
2140
2145
  scores: null;
2141
2146
  }[];
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@simonpeacocks/peacockery-voice-client",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Generated TypeScript client for the Peacockery Voice API",
5
- "type": "module",
6
- "license": "MIT",
7
5
  "repository": {
8
6
  "type": "git",
9
7
  "url": "git+https://github.com/chikingsley/peacockery-voice.git",
10
8
  "directory": "clients/typescript"
11
9
  },
10
+ "license": "MIT",
11
+ "type": "module",
12
12
  "exports": {
13
13
  ".": {
14
14
  "types": "./dist/index.d.ts",
@@ -18,10 +18,6 @@
18
18
  "files": [
19
19
  "dist"
20
20
  ],
21
- "publishConfig": {
22
- "access": "public",
23
- "provenance": false
24
- },
25
21
  "scripts": {
26
22
  "build": "tsc",
27
23
  "check": "tsc --noEmit",
@@ -32,5 +28,9 @@
32
28
  },
33
29
  "devDependencies": {
34
30
  "typescript": "^7.0.2"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "provenance": false
35
35
  }
36
36
  }