Comments (12)
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?
from speech-and-text-unity-ios-android.
@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
from speech-and-text-unity-ios-android.
I'm not sure how to set this Flag in c#/unity though :(
from speech-and-text-unity-ios-android.
Thanks! I’ll try in xcode and keep you posted.
from speech-and-text-unity-ios-android.
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).
from speech-and-text-unity-ios-android.
Are you sure? If you look at the console in xcode, you can clearly see the partial text
from speech-and-text-unity-ios-android.
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!
from speech-and-text-unity-ios-android.
@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
from speech-and-text-unity-ios-android.
DONE #32
from speech-and-text-unity-ios-android.
Thanks a lot ! I will try it this weekend.
from speech-and-text-unity-ios-android.
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
-
(id)init
{
audioEngine = [[AVAudioEngine alloc] init];
LanguageCode = @"ko-KR";
NSLocale *local =[[NSLocale alloc] initWithLocaleIdentifier:LanguageCode];
speechRecognizer = [[SFSpeechRecognizer alloc] initWithLocale:local];//for (NSLocale *locate in [SFSpeechRecognizer supportedLocales]) {
// NSLog(@"%@", [locate localizedStringForCountryCode:locate.countryCode]);
//}// Check Authorization Status
// Make sure you add "Privacy - Microphone Usage Description" key and reason in Info.plist to request micro permison
// And "NSSpeechRecognitionUsageDescription" key for requesting Speech recognize permison
[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
//The callback may not be called on the main thread. Add an operation to the main queue to update the record button's state.
dispatch_async(dispatch_get_main_queue(), ^{
switch (status) {
case SFSpeechRecognizerAuthorizationStatusAuthorized: {
NSLog(@"SUCCESS");
break;
}
case SFSpeechRecognizerAuthorizationStatusDenied: {
NSLog(@"User denied access to speech recognition");
break;
}
case SFSpeechRecognizerAuthorizationStatusRestricted: {
NSLog(@"User denied access to speech recognition");
break;
}
case SFSpeechRecognizerAuthorizationStatusNotDetermined: {
NSLog(@"User denied access to speech recognition");
break;
}
}
});}];
return self;
} -
(void)SettingSpeech: (const char *) _language
{
LanguageCode = [NSString stringWithUTF8String:_language];
NSLocale *local =[[NSLocale alloc] initWithLocaleIdentifier:LanguageCode];
speechRecognizer = [[SFSpeechRecognizer alloc] initWithLocale:local];
UnitySendMessage("SpeechToText", "onMessage", "Setting Success");
}
// recording -
(void)startRecording {
if (!audioEngine.isRunning) {
[inputNode removeTapOnBus:0];
if (recognitionTask) {
[recognitionTask cancel];
recognitionTask = nil;
}AVAudioSession *session = [AVAudioSession sharedInstance]; [session setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeMeasurement options:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; [session setActive:TRUE withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil]; [session setActive:TRUE withOptions:AVAudioSessionPortOverrideSpeaker error:nil]; inputNode = audioEngine.inputNode; recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init]; recognitionRequest.shouldReportPartialResults = YES; recognitionTask =[speechRecognizer recognitionTaskWithRequest:recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) { if (result) { NSString *transcriptText = result.bestTranscription.formattedString; //NSLog(@"STARTRECORDING RESULT: %@", transcriptText); if (result.isFinal) { UnitySendMessage("SpeechToText", "onResults", [transcriptText UTF8String]); } else { UnitySendMessage("SpeechToText", "onPartialResults", [transcriptText UTF8String]); } } else { [audioEngine stop]; recognitionTask = nil; recognitionRequest = nil; UnitySendMessage("SpeechToText", "onResults", "nil"); //NSLog(@"STARTRECORDING RESULT NULL"); } }]; AVAudioFormat *format = [inputNode outputFormatForBus:0]; [inputNode installTapOnBus:0 bufferSize:1024 format:format block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) { [recognitionRequest appendAudioPCMBuffer:buffer]; }]; [audioEngine prepare]; NSError *error1; [audioEngine startAndReturnError:&error1]; if (error1.description) { NSLog(@"errorAudioEngine.description: %@", error1.description); }
}
} -
(void)stopRecording {
if (audioEngine.isRunning) {
[inputNode removeTapOnBus:0];
[audioEngine stop];
[recognitionRequest endAudio];
if (recognitionTask) {
[recognitionTask cancel];
}
//NSLog(@"STOPRECORDING");
}
}
@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];
}
}
from speech-and-text-unity-ios-android.
@Korbain Thanks a lot!
from speech-and-text-unity-ios-android.
Related Issues (20)
- .
- Build is failing in xcode
- Registering new Vocabulary for the Speech-To-Text-Plugin to understand (IOS)
- IOS build error by undefined sumbols for arm64
- Error on Samsung S8 HOT 18
- Error SpeechRecognizer bind to recognition service failed |Android 11 HOT 11
- Build fails for iOS HOT 2
- Speech to text in android not working HOT 9
- Recents problems with Android 11 HOT 2
- Language pt-BR (Brasil) uses pt (Portugal)
- Speech to text doesn't work with popup - false (android) HOT 3
- speech to text just doesnot work
- Unity plugin speechToText not working when isShowPopupAndroid = false HOT 11
- Speech recognition not working HOT 1
- Create text in real time
- TextMeshPro not updating, does anyone know how to solve this? HOT 2
- 2 Android manifest
- Unexpected file found in Frameworks error during iOS Archiving process. HOT 1
- Android build fails
- IOS Text to Speech is not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from speech-and-text-unity-ios-android.