Skip to content

Commit 879f76a

Browse files
✨ feat: Add type annotations and refactor function exports
- Modify exports in "index.ts" to include type annotations for "useEdgeSpeech" and "useMicrosoftSpeech". - Modify export in "useOpenaiSTT/index.ts" to include a type annotation for "useOpenaiSTTWithRecord". - Remove import of "OpenaiSpeechRecognitionOptions" in "useOpenaiSTT/useOpenaiSTTWithPSR.ts". - Replace type "OpenaiSpeechRecognitionOptions" with "STTConfig" in "useOpenaiSTT/useOpenaiSTTWithRecord.ts" and "useOpenaiSTT/useOpenaiSTTWithSR.ts". - Modify function parameters to use object destructuring in "useOpenaiSTT/useOpenaiSTTWithRecord.ts" and "useOpenaiSTT/useOpenaiSTTWithSR.ts". Changes were made to add type annotations and improve code structure for better readability and maintainability.
1 parent 482d39c commit 879f76a

File tree

5 files changed

+26
-30
lines changed

5 files changed

+26
-30
lines changed

src/react/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export { useAudioVisualizer } from './hooks/useAudioVisualizer';
55
export { useBlobUrl } from './hooks/useBlobUrl';
66
export { useStreamAudioPlayer } from './hooks/useStreamAudioPlayer';
77
export { useAudioRecorder } from './useAudioRecorder';
8-
export { type EdgeSpeechOptions,useEdgeSpeech } from './useEdgeSpeech';
9-
export { type MicrosoftSpeechOptions,useMicrosoftSpeech } from './useMicrosoftSpeech';
8+
export { type EdgeSpeechOptions, useEdgeSpeech } from './useEdgeSpeech';
9+
export { type MicrosoftSpeechOptions, useMicrosoftSpeech } from './useMicrosoftSpeech';
1010
export {
1111
type OpenaiSpeechRecognitionOptions,
1212
type OpenAISTTConfig,
@@ -21,4 +21,4 @@ export {
2121
type SpeechRecognitionOptions,
2222
useSpeechRecognition,
2323
} from './useSpeechRecognition/useSpeechRecognition';
24-
export { type SpeechSynthesOptions,useSpeechSynthes } from './useSpeechSynthes';
24+
export { type SpeechSynthesOptions, useSpeechSynthes } from './useSpeechSynthes';

src/react/useOpenaiSTT/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
export { type OpenAISTTConfig, useOpenaiSTT } from './useOpenaiSTT';
22
export { useOpenaiSTTWithPSR } from './useOpenaiSTTWithPSR';
3-
export {
4-
type OpenaiSpeechRecognitionOptions,
5-
useOpenaiSTTWithRecord,
6-
} from './useOpenaiSTTWithRecord';
3+
export { type STTConfig, useOpenaiSTTWithRecord } from './useOpenaiSTTWithRecord';
74
export { useOpenaiSTTWithSR } from './useOpenaiSTTWithSR';

src/react/useOpenaiSTT/useOpenaiSTTWithPSR.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { useCallback, useState } from 'react';
33
import { useOpenaiSTT } from '@/react/useOpenaiSTT/useOpenaiSTT';
44
import { usePersistedSpeechRecognition } from '@/react/useSpeechRecognition';
55

6-
import { OpenaiSpeechRecognitionOptions, STTConfig } from './useOpenaiSTTWithRecord';
6+
import { STTConfig } from './useOpenaiSTTWithRecord';
77

88
export const useOpenaiSTTWithPSR = (
99
locale: string,
10-
config: OpenaiSpeechRecognitionOptions,
1110
{
1211
onBlobAvailable,
1312
onTextChange,
@@ -16,6 +15,7 @@ export const useOpenaiSTTWithPSR = (
1615
onFinished,
1716
onStart,
1817
onStop,
18+
options,
1919
...restConfig
2020
}: STTConfig = {},
2121
) => {
@@ -68,7 +68,7 @@ export const useOpenaiSTTWithPSR = (
6868
handleStop();
6969
onFinished?.(data, ...rest);
7070
},
71-
options: config.options!,
71+
options: options!,
7272
shouldFetch,
7373
speech: blob as Blob,
7474
...restConfig,

src/react/useOpenaiSTT/useOpenaiSTTWithRecord.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,26 @@ import { SpeechRecognitionOptions } from '@/react/useSpeechRecognition/useSpeech
77

88
import { OpenAISTTConfig } from './useOpenaiSTT';
99

10-
export type OpenaiSpeechRecognitionOptions = SpeechRecognitionOptions & Partial<OpenAISTTConfig>;
11-
12-
export interface STTConfig extends SpeechRecognitionOptions, SWRConfiguration {
10+
export interface STTConfig
11+
extends SpeechRecognitionOptions,
12+
SWRConfiguration,
13+
Partial<OpenAISTTConfig> {
1314
onFinished?: SWRConfiguration['onSuccess'];
1415
onStart?: () => void;
1516
onStop?: () => void;
1617
}
1718

18-
export const useOpenaiSTTWithRecord = (
19-
config: Partial<OpenAISTTConfig>,
20-
{
21-
onBlobAvailable,
22-
onTextChange,
23-
onSuccess,
24-
onError,
25-
onFinished,
26-
onStart,
27-
onStop,
28-
...restConfig
29-
}: STTConfig = {},
30-
) => {
19+
export const useOpenaiSTTWithRecord = ({
20+
onBlobAvailable,
21+
onTextChange,
22+
onSuccess,
23+
onError,
24+
onFinished,
25+
onStart,
26+
onStop,
27+
options,
28+
...restConfig
29+
}: STTConfig = {}) => {
3130
const [isGlobalLoading, setIsGlobalLoading] = useState<boolean>(false);
3231
const [shouldFetch, setShouldFetch] = useState<boolean>(false);
3332
const [text, setText] = useState<string>();
@@ -65,7 +64,7 @@ export const useOpenaiSTTWithRecord = (
6564
handleStop();
6665
onFinished?.(data, ...rest);
6766
},
68-
options: config.options!,
67+
options: options!,
6968
shouldFetch,
7069
speech: blob as Blob,
7170
...restConfig,

src/react/useOpenaiSTT/useOpenaiSTTWithSR.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { useCallback, useState } from 'react';
33
import { useOpenaiSTT } from '@/react/useOpenaiSTT/useOpenaiSTT';
44
import { useSpeechRecognition } from '@/react/useSpeechRecognition';
55

6-
import { OpenaiSpeechRecognitionOptions, STTConfig } from './useOpenaiSTTWithRecord';
6+
import { STTConfig } from './useOpenaiSTTWithRecord';
77

88
export const useOpenaiSTTWithSR = (
99
locale: string,
10-
config: OpenaiSpeechRecognitionOptions,
1110
{
1211
onBlobAvailable,
1312
onTextChange,
@@ -16,6 +15,7 @@ export const useOpenaiSTTWithSR = (
1615
onFinished,
1716
onStart,
1817
onStop,
18+
options,
1919
...restConfig
2020
}: STTConfig = {},
2121
) => {
@@ -68,7 +68,7 @@ export const useOpenaiSTTWithSR = (
6868
handleStop();
6969
onFinished?.(data, ...rest);
7070
},
71-
options: config.options!,
71+
options: options!,
7272
shouldFetch,
7373
speech: blob as Blob,
7474
...restConfig,

0 commit comments

Comments
 (0)