Skip to content

Commit

Permalink
Fix types version in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mnemitz committed Feb 26, 2025
1 parent 0488e57 commit 1bdb27d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 24 deletions.
6 changes: 3 additions & 3 deletions examples/nextjs-real-time-transcription/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import {
getFeatures,
RealtimeTranscriptionProvider,
} from '@speechmatics/real-time-client-react';
import { PCMAudioRecorderProvider } from '@speechmatics/browser-audio-input-react';
import type { Metadata } from 'next';
import { Controls } from '@/components/Controls';
import { Output } from '@/components/Output';
import { Status } from '@/components/Status';
import { AudioProvider } from '@/components/AudioProvider';

export const metadata: Metadata = {
title: 'Speechmatics Real-time example',
Expand All @@ -21,7 +21,7 @@ export default async function Page() {
);

return (
<PCMAudioRecorderProvider workletScriptURL="/js/pcm-audio-worklet.min.js">
<AudioProvider>
<RealtimeTranscriptionProvider appId="nextjs-rt-example">
<section>
<h3>Real-time Example</h3>
Expand All @@ -34,6 +34,6 @@ export default async function Page() {
</section>
</section>
</RealtimeTranscriptionProvider>
</PCMAudioRecorderProvider>
</AudioProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client';

import { useAudioContext } from '@/lib/hooks/useAudioContext';
import { PCMAudioRecorderProvider } from '@speechmatics/browser-audio-input-react';
import type { PropsWithChildren } from 'react';

export function AudioProvider({ children }: PropsWithChildren) {
const audioContext = useAudioContext();

return (
<PCMAudioRecorderProvider
audioContext={audioContext}
workletScriptURL="/js/pcm-audio-worklet.min.js"
>
{children}
</PCMAudioRecorderProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useEffect, useMemo, useSyncExternalStore } from 'react';
import { RECORDING_SAMPLE_RATE } from '../constants';

export function useAudioContext() {
const hydrated = useHydrated();
const audioContext = useMemo(
() =>
hydrated
? new window.AudioContext({ sampleRate: RECORDING_SAMPLE_RATE })
: undefined,
[hydrated],
);

useCleanupAudioContext(audioContext);

return audioContext;
}

// Lets us know if we're rendering client side or not
const useHydrated = () =>
useSyncExternalStore(
() => () => {},
() => true,
() => false,
);

// Close audio context when component unmounts
function useCleanupAudioContext(context?: AudioContext) {
useEffect(() => {
return () => {
if (context && context.state !== 'closed') {
context.close();
}
};
}, [context]);
}
3 changes: 1 addition & 2 deletions examples/nextjs-real-time-transcription/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/react": "^19.0.10",
"copy-webpack-plugin": "^12.0.2",
"typescript": "^5"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-audio-input-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"react": "^18 || ^19"
},
"devDependencies": {
"@types/react": "^18.3.12",
"@types/react": "^19.0.10",
"typescript-event-target": "^1.1.1"
}
}
7 changes: 6 additions & 1 deletion packages/web-pcm-player-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,9 @@ export default function Index() {
);
}

```
```


## React context

This
2 changes: 1 addition & 1 deletion packages/web-pcm-player-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"react": "^18 || ^19"
},
"devDependencies": {
"@types/react": "^18.3.12",
"@types/react": "^19.0.10",
"typescript-event-target": "^1.1.1"
}
}
29 changes: 13 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1bdb27d

Please sign in to comment.