AJITHKUMAR
AJITHKUMAR

Reputation: 21

In objective-c SFSpeechRecognizer resultHandler is not work properly when request type is OnDeviceTranscript?

I uploaded a 2-minute audio file, and the transcript results began after half of the audio was processed. However, the result.formattedString started a new string instead of appending to the already transcribed text.

This issue occur only onDeviceTranscript, How to fix it? enter image description here

NSLocale *locale =[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] firstObject]];
            SFSpeechRecognizer* recognizer = [[SFSpeechRecognizer alloc] initWithLocale:locale];
            SFSpeechURLRecognitionRequest* request = [[SFSpeechURLRecognitionRequest alloc] initWithURL:[NSURL fileURLWithPath:filePath]];

            if(device){
                request.requiresOnDeviceRecognition = YES;
            }

            [recognizer recognitionTaskWithRequest:request resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
                if (error) {
                    convertedString(textString);
                }
                else {
                    textString = [[result bestTranscription] formattedString];
                }
                if (result.isFinal)
                {
                    convertedString([[result bestTranscription] formattedString]);
                }
            }];

Upvotes: 0

Views: 48

Answers (0)

Related Questions