Skip to content

Commit cd19e7c

Browse files
committed
Add discovery endpoint to real time client + react
1 parent d6c10d0 commit cd19e7c

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

examples/nextjs/src/app/real-time/Controls.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,13 @@ import { LanguageSelect } from './LanguageSelect';
1616

1717
export function Controls({
1818
languages,
19-
}: { languages: [code: string, displayName: string][] }) {
20-
const { startTranscription, stopTranscription, sendAudio, socketState } =
19+
}: { languages: (readonly [code: string, displayName: string])[] }) {
20+
const { startTranscription, stopTranscription, sendAudio } =
2121
useRealtimeTranscription();
2222

2323
const { isRecording, startRecording, stopRecording } = usePcmAudioRecorder();
2424

2525
usePcmAudioListener(sendAudio);
26-
// Cleanup
27-
useEffect(() => {
28-
return () => {
29-
stopTranscription();
30-
stopRecording();
31-
};
32-
}, [stopTranscription, stopRecording]);
3326

3427
const startSession = useCallback(
3528
async ({
@@ -59,6 +52,14 @@ export function Controls({
5952
[startSession],
6053
);
6154

55+
// Cleanup
56+
useEffect(() => {
57+
return () => {
58+
stopTranscription();
59+
stopRecording();
60+
};
61+
}, [stopTranscription, stopRecording]);
62+
6263
return (
6364
<article>
6465
<form onSubmit={handleSubmit}>

examples/nextjs/src/app/real-time/LanguageSelect.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
export function LanguageSelect({
22
languages,
33
disabled,
4-
}: { languages: [code: string, displayName: string][]; disabled?: boolean }) {
4+
}: {
5+
languages: (readonly [code: string, displayName: string])[];
6+
disabled?: boolean;
7+
}) {
58
return (
69
<label>
710
Select language

examples/nextjs/src/app/real-time/page.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { RealtimeTranscriptionProvider } from '@speechmatics/real-time-client-react';
1+
import {
2+
getFeatures,
3+
RealtimeTranscriptionProvider,
4+
} from '@speechmatics/real-time-client-react';
25
import { PcmAudioRecorderProvider } from '@speechmatics/browser-audio-input-react';
36
import { Controls } from './Controls';
47
import { Status } from './Status';
@@ -11,15 +14,10 @@ export const metadata: Metadata = {
1114
};
1215

1316
export default async function Page() {
14-
const resp = await fetch(
15-
'https://asr.api.speechmatics.com/v1/discovery/features',
16-
);
17-
17+
const features = await getFeatures();
1818
const displayNames = new Intl.DisplayNames(['en'], { type: 'language' });
19-
20-
// TODO figure out if there's an RT specific discovery endpoint
21-
const languages = (await resp.json()).batch.transcription[0].languages.map(
22-
(code: string) => [code, displayNames.of(code)] as const,
19+
const languages = features.realtime.transcription[0].languages.map(
20+
(code) => [code, displayNames.of(code) ?? code] as const,
2321
);
2422

2523
return (

packages/real-time-client-react/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export * from './use-real-time-transcription';
22
export * from './use-real-time-event-listener';
33
export * from './real-time-context';
44
export * from './real-time-transcription-provider';
5-
export type * from '@speechmatics/real-time-client';
5+
export * from '@speechmatics/real-time-client';

0 commit comments

Comments
 (0)