@@ -65,24 +65,29 @@ export const useSpeechToText = ({
6565 [ isReady , isGenerating , modelInstance ]
6666 ) ;
6767
68- const stream = useCallback ( async ( options ?: DecodingOptions ) => {
69- if ( ! isReady ) throw new Error ( getError ( ETError . ModuleNotLoaded ) ) ;
70- if ( isGenerating ) throw new Error ( getError ( ETError . ModelGenerating ) ) ;
71- setIsGenerating ( true ) ;
72- setCommittedTranscription ( '' ) ;
73- setNonCommittedTranscription ( '' ) ;
74- let transcription = '' ;
75- try {
76- for await ( const { committed, nonCommitted } of modelInstance . stream ( options ) ) {
77- setCommittedTranscription ( ( prev ) => prev + committed ) ;
78- setNonCommittedTranscription ( nonCommitted ) ;
79- transcription += committed ;
68+ const stream = useCallback (
69+ async ( options ?: DecodingOptions ) => {
70+ if ( ! isReady ) throw new Error ( getError ( ETError . ModuleNotLoaded ) ) ;
71+ if ( isGenerating ) throw new Error ( getError ( ETError . ModelGenerating ) ) ;
72+ setIsGenerating ( true ) ;
73+ setCommittedTranscription ( '' ) ;
74+ setNonCommittedTranscription ( '' ) ;
75+ let transcription = '' ;
76+ try {
77+ for await ( const { committed, nonCommitted } of modelInstance . stream (
78+ options
79+ ) ) {
80+ setCommittedTranscription ( ( prev ) => prev + committed ) ;
81+ setNonCommittedTranscription ( nonCommitted ) ;
82+ transcription += committed ;
83+ }
84+ } finally {
85+ setIsGenerating ( false ) ;
8086 }
81- } finally {
82- setIsGenerating ( false ) ;
83- }
84- return transcription ;
85- } , [ isReady , isGenerating , modelInstance ] ) ;
87+ return transcription ;
88+ } ,
89+ [ isReady , isGenerating , modelInstance ]
90+ ) ;
8691
8792 const wrapper = useCallback (
8893 < T extends ( ...args : any [ ] ) => any > ( fn : T ) => {
0 commit comments