【问题标题】:Simple Speech into Text in IPhone在 iPhone 中将简单的语音转换为文本
【发布时间】:2016-12-17 03:41:42
【问题描述】:

我正在尝试将语音等应用程序开发为文本,我想将语音转换为文本字段中的文本。我在谷歌中搜索了一些示例代码,但没有用。我得到了这些链接,@987654321 @,但在此他们提到一些 API 用于语音识别,但我无法得到。

请任何人都可以与示例项目分享一个教程,它可能对我非常有用。

提前致谢!!!

【问题讨论】:

  • “给我找个教程”不是 stackoverflow 的合适主题。
  • @EI Tomato,请告诉我怎么做,我对此一无所知
  • @AgalSivamanoj 在该教程中,他们使用的是由“Nuance Developers”开发的“SpeechKit”。如果您无法理解或难以理解,那么您可以在您的项目中使用“语音”。如需更多参考,您可以使用本教程“appcoda.com/siri-speech-framework”。
  • @unexpextedNil ,此链接无效

标签: objective-c speech-to-text


【解决方案1】:
- (void) viewDidAppear:(BOOL)animated {

_recognizer = [[SFSpeechRecognizer alloc] initWithLocale:[NSLocale localeWithLocaleIdentifier:@"en-US"]];
[_recognizer setDelegate:self];
[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus authStatus) {
    switch (authStatus) {
        case SFSpeechRecognizerAuthorizationStatusAuthorized:
            //User gave access to speech recognition
            NSLog(@"Authorized");
            break;

        case SFSpeechRecognizerAuthorizationStatusDenied:
            //User denied access to speech recognition
            NSLog(@"SFSpeechRecognizerAuthorizationStatusDenied");
            break;

        case SFSpeechRecognizerAuthorizationStatusRestricted:
            //Speech recognition restricted on this device
            NSLog(@"SFSpeechRecognizerAuthorizationStatusRestricted");
            break;

        case SFSpeechRecognizerAuthorizationStatusNotDetermined:
            //Speech recognition not yet authorized

            break;

        default:
            NSLog(@"Default");
            break;
    }
}];

audioEngine = [[AVAudioEngine alloc] init];
_speechSynthesizer  = [[AVSpeechSynthesizer alloc] init];         
[_speechSynthesizer setDelegate:self];
}


-(void)startRecording
{
[self clearLogs:nil];

NSError * outError;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:&outError];
[audioSession setMode:AVAudioSessionModeMeasurement error:&outError];
[audioSession setActive:true withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation  error:&outError];

request2 = [[SFSpeechAudioBufferRecognitionRequest alloc] init];

inputNode = [audioEngine inputNode];

if (request2 == nil) {
    NSLog(@"Unable to created a SFSpeechAudioBufferRecognitionRequest object");
}

if (inputNode == nil) {

    NSLog(@"Unable to created a inputNode object");
}

request2.shouldReportPartialResults = true;

_currentTask = [_recognizer recognitionTaskWithRequest:request2
                delegate:self];

[inputNode installTapOnBus:0 bufferSize:4096 format:[inputNode outputFormatForBus:0] block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when){
    NSLog(@"Block tap!");

    [request2 appendAudioPCMBuffer:buffer];

}];

    [audioEngine prepare];
    [audioEngine startAndReturnError:&outError];
    NSLog(@"Error %@", outError);
}

- (void)speechRecognitionTask:(SFSpeechRecognitionTask *)task didFinishRecognition:(SFSpeechRecognitionResult *)result {

NSLog(@"speechRecognitionTask:(SFSpeechRecognitionTask *)task didFinishRecognition");
NSString * translatedString = [[[result bestTranscription] formattedString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

[self log:translatedString];

if ([result isFinal]) {
    [audioEngine stop];
    [inputNode removeTapOnBus:0];
    _currentTask = nil;
    request2 = nil;
}
}

【讨论】:

  • 谢谢,user7306261,有一个疑问,我必须在哪里执行此代码,您是否使用过任何框架?
  • 什么是 SFSpeechRecognizer ,在这里,如果我这样做,它会显示错误,例如使用未标记的标识符 SFSpeechRecognizer,请告诉我,如何做到这一点..
  • 您好,它在 [inputNodeEngine installTapOnBus:0 bufferSize:4096 格式:[inputNodeEngine outputFormatForBus:0] block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when){ } 中显示错误。我想要目标c。请帮助我
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多