Title: [272284] branches/safari-611-branch/Source/WebCore
Revision
272284
Author
[email protected]
Date
2021-02-02 17:41:35 -0800 (Tue, 02 Feb 2021)

Log Message

Cherry-pick r271958. rdar://problem/73887977

    Use SFTranscription instead of SFTranscriptionSegment for SpeechRecognitionAlternative
    https://bugs.webkit.org/show_bug.cgi?id=221026

    Patch by Sihui Liu <[email protected]> on 2021-01-27
    Reviewed by Youenn Fablet.

    So SpeechRecognitionAlternative contains a sentence instead of a word, which matches Blink's behavior.

    Manually tested in MiniBrowser.

    * Modules/speech/cocoa/WebSpeechRecognizerTask.mm:
    (-[WebSpeechRecognizerTaskImpl callbackWithTranscriptions:isFinal:]):
    (-[WebSpeechRecognizerTaskImpl speechRecognitionTask:didHypothesizeTranscription:]):
    (-[WebSpeechRecognizerTaskImpl speechRecognitionTask:didFinishRecognition:]):
    (-[WebSpeechRecognizerTaskImpl callbackWithResult:isFinal:]): Deleted.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271958 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-611-branch/Source/WebCore/ChangeLog (272283 => 272284)


--- branches/safari-611-branch/Source/WebCore/ChangeLog	2021-02-03 01:41:32 UTC (rev 272283)
+++ branches/safari-611-branch/Source/WebCore/ChangeLog	2021-02-03 01:41:35 UTC (rev 272284)
@@ -1,5 +1,44 @@
 2021-02-02  Alan Coon  <[email protected]>
 
+        Cherry-pick r271958. rdar://problem/73887977
+
+    Use SFTranscription instead of SFTranscriptionSegment for SpeechRecognitionAlternative
+    https://bugs.webkit.org/show_bug.cgi?id=221026
+    
+    Patch by Sihui Liu <[email protected]> on 2021-01-27
+    Reviewed by Youenn Fablet.
+    
+    So SpeechRecognitionAlternative contains a sentence instead of a word, which matches Blink's behavior.
+    
+    Manually tested in MiniBrowser.
+    
+    * Modules/speech/cocoa/WebSpeechRecognizerTask.mm:
+    (-[WebSpeechRecognizerTaskImpl callbackWithTranscriptions:isFinal:]):
+    (-[WebSpeechRecognizerTaskImpl speechRecognitionTask:didHypothesizeTranscription:]):
+    (-[WebSpeechRecognizerTaskImpl speechRecognitionTask:didFinishRecognition:]):
+    (-[WebSpeechRecognizerTaskImpl callbackWithResult:isFinal:]): Deleted.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271958 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-01-27  Sihui Liu  <[email protected]>
+
+            Use SFTranscription instead of SFTranscriptionSegment for SpeechRecognitionAlternative
+            https://bugs.webkit.org/show_bug.cgi?id=221026
+
+            Reviewed by Youenn Fablet.
+
+            So SpeechRecognitionAlternative contains a sentence instead of a word, which matches Blink's behavior.
+
+            Manually tested in MiniBrowser.
+
+            * Modules/speech/cocoa/WebSpeechRecognizerTask.mm:
+            (-[WebSpeechRecognizerTaskImpl callbackWithTranscriptions:isFinal:]):
+            (-[WebSpeechRecognizerTaskImpl speechRecognitionTask:didHypothesizeTranscription:]):
+            (-[WebSpeechRecognizerTaskImpl speechRecognitionTask:didFinishRecognition:]):
+            (-[WebSpeechRecognizerTaskImpl callbackWithResult:isFinal:]): Deleted.
+
+2021-02-02  Alan Coon  <[email protected]>
+
         Cherry-pick r271930. rdar://problem/73886919
 
     REGRESSION (r271584): Hovering slowly over and out of "Top 100" items on liberation.fr does not restore animated state

Modified: branches/safari-611-branch/Source/WebCore/Modules/speech/cocoa/WebSpeechRecognizerTask.mm (272283 => 272284)


--- branches/safari-611-branch/Source/WebCore/Modules/speech/cocoa/WebSpeechRecognizerTask.mm	2021-02-03 01:41:32 UTC (rev 272283)
+++ branches/safari-611-branch/Source/WebCore/Modules/speech/cocoa/WebSpeechRecognizerTask.mm	2021-02-03 01:41:35 UTC (rev 272284)
@@ -56,7 +56,7 @@
 }
 
 - (instancetype)initWithIdentifier:(SpeechRecognitionConnectionClientIdentifier)identifier locale:(NSString*)localeIdentifier doMultipleRecognitions:(BOOL)continuous reportInterimResults:(BOOL)interimResults maxAlternatives:(unsigned long)alternatives delegateCallback:(void(^)(const SpeechRecognitionUpdate&))callback;
-- (void)callbackWithResult:(SFTranscription *)transcription isFinal:(BOOL)isFinal;
+- (void)callbackWithTranscriptions:(NSArray<SFTranscription *> *)transcriptions isFinal:(BOOL)isFinal;
 - (void)audioSamplesAvailable:(CMSampleBufferRef)sampleBuffer;
 - (void)abort;
 - (void)stop;
@@ -113,24 +113,23 @@
     return self;
 }
 
-- (void)callbackWithResult:(SFTranscription *)transcription isFinal:(BOOL)isFinal
+- (void)callbackWithTranscriptions:(NSArray<SFTranscription *> *)transcriptions isFinal:(BOOL)isFinal
 {
-    auto segments = [transcription segments];
-    Vector<SpeechRecognitionResultData> datas;
-    datas.reserveInitialCapacity(segments.count);
-    for (SFTranscriptionSegment* segment in segments) {
-        // Note segment confidence is reported 0 when result is not final.
-        Vector<SpeechRecognitionAlternativeData> alternatives;
-        alternatives.reserveInitialCapacity(_maxAlternatives);
-        alternatives.uncheckedAppend(SpeechRecognitionAlternativeData { [segment substring], [segment confidence] });
-        for (NSString* segmentAlternative : [segment alternativeSubstrings]) {
-            if (alternatives.size() == _maxAlternatives)
-                break;
-            // FIXME: calculate or get alternative confidence if possible.
-            alternatives.uncheckedAppend(SpeechRecognitionAlternativeData { segmentAlternative, 0.0 });
+    Vector<SpeechRecognitionAlternativeData> alternatives;
+    alternatives.reserveInitialCapacity(_maxAlternatives);
+    for (SFTranscription* transcription in transcriptions) {
+        // FIXME: <rdar://73629573> get confidence of SFTranscription when possible.
+        double maxConfidence = 0.0;
+        for (SFTranscriptionSegment* segment in [transcription segments]) {
+            double confidence = [segment confidence];
+            maxConfidence = maxConfidence < confidence ? confidence : maxConfidence;
         }
-        datas.uncheckedAppend(SpeechRecognitionResultData { WTFMove(alternatives), bool(isFinal) });
+        alternatives.uncheckedAppend(SpeechRecognitionAlternativeData { [transcription formattedString], maxConfidence });
+        if (alternatives.size() == _maxAlternatives)
+            break;
     }
+    Vector<SpeechRecognitionResultData> datas;
+    datas.append(SpeechRecognitionResultData { WTFMove(alternatives), bool(isFinal) });
     _delegateCallback(SpeechRecognitionUpdate::createResult(_identifier, WTFMove(datas)));
 }
 
@@ -219,15 +218,14 @@
     ASSERT(isMainThread());
 
     [self sendSpeechStartIfNeeded];
-    [self callbackWithResult:transcription isFinal:NO];
+    [self callbackWithTranscriptions:[NSArray arrayWithObjects:transcription, nil] isFinal:NO];
 }
 
 - (void)speechRecognitionTask:(SFSpeechRecognitionTask *)task didFinishRecognition:(SFSpeechRecognitionResult *)recognitionResult
 {
     ASSERT(isMainThread());
+    [self callbackWithTranscriptions:recognitionResult.transcriptions isFinal:YES];
 
-    [self callbackWithResult:recognitionResult.bestTranscription isFinal:YES];
-
     if (!_doMultipleRecognitions) {
         [self sendSpeechEndIfNeeded];
         [self sendEndIfNeeded];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to