@@ -80,52 +80,6 @@ public function tokenize(string $text, int $maxTokens): array
8080 return $ output ;
8181 }
8282
83- /**
84- * Split the input audio in chunks and process each chunk separately using whisper_full_with_state()
85- *
86- * Result is stored in the default state of the context
87- * Not thread safe if executed in parallel on the same context.
88- * It seems this approach can offer some speedup in some cases.
89- * However, the transcription accuracy can be worse at the beginning and end of each chunk.
90- *
91- * @param float[] $pcm Raw PCM audio data, 32 bit floating point at a sample rate of 16 kHz, 1 channel.
92- * @param WhisperFullParams $params The parameters to use.
93- * @param int $nProcessors The number of processors to use.
94- */
95- public function fullParallel (array $ pcm , WhisperFullParams $ params , int $ nProcessors ): void
96- {
97- if (empty ($ pcm )) {
98- // can randomly trigger segmentation faults if we don't check this
99- throw WhisperException::noSamples ();
100- }
101-
102- $ pcmSize = count ($ pcm );
103- $ samples = $ this ->ffi ->new ("float[ $ pcmSize] " );
104-
105- foreach ($ pcm as $ i => $ sample ) {
106- $ samples [$ i ] = $ sample ;
107- }
108-
109- $ cParams = $ params ->toCStruct ($ this ->ffi );
110- $ result = $ this ->ffi ->whisper_full_parallel (
111- $ this ->ctx ,
112- $ cParams ,
113- $ this ->ffi ->cast ('float * ' , $ samples ),
114- $ pcmSize ,
115- $ nProcessors
116- );
117-
118- match ($ result ) {
119- -1 , -2 => throw WhisperException::failedToCalculateSpectrogram (),
120- -3 => throw WhisperException::failedToAutoDetectLanguage (),
121- -5 => throw WhisperException::audioCtxLongerThanMax ($ params ->audioCtx , $ this ->modelNAudioCtx ()),
122- -6 => WhisperException::failedToEncode (),
123- -7 , -8 => WhisperException::failedToDecode (),
124- 0 => null ,
125- default => throw WhisperException::genericError ($ result )
126- };
127- }
128-
12983 /**
13084 * Return the number of tokens in the vocabulary
13185 */
@@ -490,7 +444,11 @@ private function setupLoggerCallback(): void
490444 } else {
491445 $ logCallback = function (int $ level , string $ message , ?CData $ user_data ) use ($ logger ) {
492446 $ psrLevel = (LogLevel::tryFrom ($ level ) ?? LogLevel::INFO )->toPsrLogLevel ();
493- $ logger ->log ($ psrLevel , $ message );
447+ try {
448+ $ logger ->log ($ psrLevel , $ message );
449+ } catch (\Throwable $ e ) {
450+ fwrite (STDERR , $ e ->getMessage ());
451+ }
494452 };
495453 }
496454
0 commit comments