Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions packages/client/src/scribe/scribe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,62 @@ describe("Scribe", () => {
server.close();
});

it("builds URI with enableLogging set to false", () => {
const server = new Server(
"wss://api.elevenlabs.io/v1/speech-to-text/realtime?model_id=scribe_v2_realtime&token=sutkn_123&enable_logging=false"
);

const connection = Scribe.connect({
token: TEST_TOKEN,
modelId: TEST_MODEL_ID,
audioFormat: AudioFormat.PCM_16000,
sampleRate: 16000,
enableLogging: false,
});

expect(connection).toBeDefined();

connection.close();
server.close();
Comment on lines +109 to +110

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just extends an existing pattern, but closing of test servers should really be a part of an after each hook to prevent cross-talking between tests (in case the test throws midway).

});

it("builds URI with enableLogging set to true", () => {
const server = new Server(
"wss://api.elevenlabs.io/v1/speech-to-text/realtime?model_id=scribe_v2_realtime&token=sutkn_123&enable_logging=true"
);

const connection = Scribe.connect({
token: TEST_TOKEN,
modelId: TEST_MODEL_ID,
audioFormat: AudioFormat.PCM_16000,
sampleRate: 16000,
enableLogging: true,
});

expect(connection).toBeDefined();

connection.close();
server.close();
});

it("omits enable_logging from URI when not specified", () => {
const server = new Server(
"wss://api.elevenlabs.io/v1/speech-to-text/realtime?model_id=scribe_v2_realtime&token=sutkn_123"
);

const connection = Scribe.connect({
token: TEST_TOKEN,
modelId: TEST_MODEL_ID,
audioFormat: AudioFormat.PCM_16000,
sampleRate: 16000,
});

expect(connection).toBeDefined();

connection.close();
server.close();
});

it("throws error when modelId is missing", () => {
expect(() => {
Scribe.connect({
Expand Down
11 changes: 11 additions & 0 deletions packages/client/src/scribe/scribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ interface BaseOptions {
* @default false
*/
includeTimestamps?: boolean;
/**
* Whether to enable logging for this session.
* When set to false, logging will be disabled.
*/
enableLogging?: boolean;
}

export interface AudioOptions extends BaseOptions {
Expand Down Expand Up @@ -172,6 +177,12 @@ export class ScribeRealtime {
options.includeTimestamps ? "true" : "false"
);
}
if (options.enableLogging !== undefined) {
params.append(
"enable_logging",
options.enableLogging ? "true" : "false"
);
}

const queryString = params.toString();
return queryString ? `${baseUri}?${queryString}` : baseUri;
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/scribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export interface ScribeHookOptions extends ScribeCallbacks {

// Include timestamps
includeTimestamps?: boolean;

// Logging
enableLogging?: boolean;
}

export interface UseScribeReturn {
Expand Down Expand Up @@ -186,6 +189,9 @@ export function useScribe(options: ScribeHookOptions = {}): UseScribeReturn {

// Timestamps
includeTimestamps: defaultIncludeTimestamps,

// Logging
enableLogging: defaultEnableLogging,
} = options;

const connectionRef = useRef<RealtimeConnection | null>(null);
Expand Down Expand Up @@ -242,6 +248,9 @@ export function useScribe(options: ScribeHookOptions = {}): UseScribeReturn {
onCommittedTranscriptWithTimestamps
);

const enableLogging =
runtimeOptions.enableLogging ?? defaultEnableLogging;

if (microphone) {
// Microphone mode
connection = Scribe.connect({
Expand All @@ -262,6 +271,7 @@ export function useScribe(options: ScribeHookOptions = {}): UseScribeReturn {
languageCode: runtimeOptions.languageCode || defaultLanguageCode,
microphone,
includeTimestamps,
enableLogging,
} as MicrophoneOptions);
} else if (audioFormat && sampleRate) {
// Manual audio mode
Expand All @@ -282,6 +292,7 @@ export function useScribe(options: ScribeHookOptions = {}): UseScribeReturn {
defaultMinSilenceDurationMs,
languageCode: runtimeOptions.languageCode || defaultLanguageCode,
includeTimestamps,
enableLogging,
audioFormat,
sampleRate,
} as AudioOptions);
Expand Down Expand Up @@ -464,6 +475,7 @@ export function useScribe(options: ScribeHookOptions = {}): UseScribeReturn {
defaultAudioFormat,
defaultSampleRate,
defaultIncludeTimestamps,
defaultEnableLogging,
onSessionStarted,
onPartialTranscript,
onCommittedTranscript,
Expand Down
Loading