Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proper partial s2t for less latency on iOS #32

Merged
merged 1 commit into from
Oct 7, 2020

Conversation

calvma
Copy link
Contributor

@calvma calvma commented Oct 6, 2020

for issue #29 . Currently, iOS speech to text waits until after audio is done recording to do the translation as opposed to while audio is being recorded. By simply moving around the speech recognizer code, getting text back in to unity happens way faster, thus improving the app experience in iOS

@khanhuitse05 khanhuitse05 merged commit 7b66000 into khanhuitse05:master Oct 7, 2020
@Korbain
Copy link

Korbain commented Oct 9, 2020

Hi Michael,

Thanks very much. I got it to work! I did have to do 2 changes, however, to get to work.
1)
In SpeechRecorderViewController.mm, you need to add an else statement (or else, since you are waiting for the isFinal flag, the partial results never get sent to Unity):

            if (result.isFinal) {
                UnitySendMessage("SpeechToText", "onResults", [transcriptText UTF8String]);
            }
            else
            {
                UnitySendMessage("SpeechToText", "onPartialResults", [transcriptText UTF8String]);
            }

In TextSpeech.cs, you need to add the onPartialResults for iOS. Currently this code exists but only for IF_UNITY_ANDROID.
Just move code out of the define so that it becomes available for iOS as well.

I am talking about this code:

    public Action<string> onPartialResultsCallback;
    /** Called when partial recognition results are available. */
    public void onPartialResults(string _params)
    {
        if (onPartialResultsCallback != null)
            onPartialResultsCallback(_params);
    }

Thanks again,

Korbain

1 similar comment
@Korbain
Copy link

Korbain commented Oct 9, 2020

Hi Michael,

Thanks very much. I got it to work! I did have to do 2 changes, however, to get to work.
1)
In SpeechRecorderViewController.mm, you need to add an else statement (or else, since you are waiting for the isFinal flag, the partial results never get sent to Unity):

            if (result.isFinal) {
                UnitySendMessage("SpeechToText", "onResults", [transcriptText UTF8String]);
            }
            else
            {
                UnitySendMessage("SpeechToText", "onPartialResults", [transcriptText UTF8String]);
            }

In TextSpeech.cs, you need to add the onPartialResults for iOS. Currently this code exists but only for IF_UNITY_ANDROID.
Just move code out of the define so that it becomes available for iOS as well.

I am talking about this code:

    public Action<string> onPartialResultsCallback;
    /** Called when partial recognition results are available. */
    public void onPartialResults(string _params)
    {
        if (onPartialResultsCallback != null)
            onPartialResultsCallback(_params);
    }

Thanks again,

Korbain

@Korbain
Copy link

Korbain commented Oct 10, 2020

In addition, you need to stop the recognizer task in StopRecording or else it will continuously spam you with the same results

  • (void)stopRecording {
    if (audioEngine.isRunning) {
    [inputNode removeTapOnBus:0];
    [audioEngine stop];
    [recognitionRequest endAudio];
    if (recognitionTask) {
    [recognitionTask cancel];
    }

    NSLog(@"STOPRECORDING");
    }
    }

@anita-web
Copy link

Hi @Korbain, I am a design student studying AR and I've been using the plugin for my project and it's been super helpful! Very glad it exists. I've been following a few youtube tutorials but now would really love to get partial s2t to work in my project but can't quite seem to understand how to get the partial results to unity. I don't know if you have time for a random stranger but would really appreciate some help! - Ana

@Korbain
Copy link

Korbain commented Feb 15, 2021

Hi Anita, sure. I’ll see what I can do to help. Did you do/understand the 3 points I identified above?

@Znoleg
Copy link

Znoleg commented Mar 4, 2021

@Korbain Hi, Korbain! Thanks for your input and information.
But i didn't understand where to put your listed changes. I've never worked in swift + I don't quite understand how this code works :) So, can you just send me "SpeechRecorderViewController.mm" file?
Thanks!

@Korbain
Copy link

Korbain commented Mar 4, 2021 via email

@reezoobose reezoobose mentioned this pull request Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants