khanhuitse05 / speech-and-text-unity-ios-android

Speed to text in Unity iOS use Native Speech Recognition
MIT License
288 stars 124 forks source link

Implement Partial Results for iOS #29

Closed Korbain closed 2 years ago

Korbain commented 3 years ago

Hi,

Thanks for the excellent work. Could someone add support for partial results for IOS? I would like to have continuous speech recognition and with this method, it could be achieved. I would simply send a stop listening followed immediately by a start listening after 1 second or so of no changes in the partial results, indicating a pause in speaking.

Let me know. Thanks!

calvma commented 3 years ago

image

It's one more line to enable partial results in swift. Is it possible to make onPartialResultsCallback method available for iOS as well as Android?

calvma commented 3 years ago

@Korbain figured out where to set the flag in xcode to do partial results! Just change the value on line 90 from NO to YES

image

calvma commented 3 years ago

I'm not sure how to set this Flag in c#/unity though :(

Korbain commented 3 years ago

Thanks! I’ll try in xcode and keep you posted.

Korbain commented 3 years ago

Ok I set this flag in xcode but it is insufficient. I believe onResults is only called when stopRecording is called. Ie the onpartialresults callback is not implemented. Unfortunately, this is beyond my pay grade. If anyone knows how to do this end to end I would appreciate (for Unity).

calvma commented 3 years ago

Are you sure? If you look at the console in xcode, you can clearly see the partial text

image

calvma commented 3 years ago

Also, the SpeechRecorderViewController.mm file lives in the unity repo as well in case you'd rather make changes to the file in this repo as opposed to in the xcode build!

calvma commented 3 years ago

@Korbain I see what you're saying now!

So I don't think onResults() is the issue. The issue is that speech recognition is called in stopRecording(). If I'm able to figure out how to reorient the obj-c code to run speech recognition in startRecording() and check for result.isFinal then I'll do a pull request!

I'm not sure what your pay grade is, but see this github sample project with an example

calvma commented 3 years ago

DONE https://github.com/PingAK9/Speech-And-Text-Unity-iOS-Android/pull/32

Korbain commented 3 years ago

Thanks a lot ! I will try it this weekend.

Korbain commented 3 years ago

Hi, A few people have asked for my version, so here it is:

// // SpeechRecorderViewController.m // SpeechToText //

import "SpeechRecorderViewController.h"

import <Speech/Speech.h>

@interface SpeechRecorderViewController () {
// Speech recognize SFSpeechRecognizer speechRecognizer; SFSpeechAudioBufferRecognitionRequest recognitionRequest; SFSpeechRecognitionTask recognitionTask; // Record speech using audio Engine AVAudioInputNode inputNode; AVAudioEngine audioEngine; NSString LanguageCode;

} @end

@implementation SpeechRecorderViewController

@end extern "C"{ SpeechRecorderViewController vc = [[SpeechRecorderViewController alloc] init]; void _TAG_startRecording(){ [vc startRecording]; }
void _TAG_stopRecording(){ [vc stopRecording]; }
void _TAG_SettingSpeech(const char
_language){ [vc SettingSpeech:_language]; }
}

Znoleg commented 3 years ago

@Korbain Thanks a lot!