Last active
August 29, 2015 14:09
-
-
Save inobo55/0098474a113a7c8f67e4 to your computer and use it in GitHub Desktop.
音声認識 by docomo [Objective-C]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// VoiceTest | |
// | |
// Created by inobo52 on 2014/11/10. | |
// Copyright (c) 2014年 inobo. All rights reserved. | |
// | |
#import "ViewController.h" | |
#import <AVFoundation/AVFoundation.h> | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
//storyboardにbtnを設置.ボタンを押したときに以下のメソッドを実行 | |
- (IBAction)btnTouched:(id)sender { | |
AVAudioSession *session = [AVAudioSession sharedInstance]; | |
[session setCategory:AVAudioSessionCategoryRecord error:nil]; | |
NSMutableDictionary *setting = [NSMutableDictionary dictionary]; | |
[setting setObject:@"SET_YOUR_DOCOMO_API_KEY_YEEEEEE" forKey:@"api_key"]; | |
[setting setObject:[[NSNumber alloc] initWithInt:1] forKey:@"sbm_mode"]; | |
SRClientHelper *client = [[SRClientHelper alloc] initWithDevice:setting]; | |
client.delegate = self; | |
[client start]; | |
} | |
- (void)srcDidRecognize:(NSData*)data | |
{ | |
NSLog(@".......... srcDidRecognize"); | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"認識結果" | |
message:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] | |
delegate:nil | |
cancelButtonTitle:nil | |
otherButtonTitles:@"OK", nil]; | |
[alert show]; | |
} | |
- (void)srcDidReady | |
{ | |
NSLog(@".......... srcDidReady"); | |
} | |
- (void)srcDidSentenceEnd | |
{ | |
NSLog(@".......... srcDidSentenceEnd"); | |
} | |
- (void)srcDidComplete:(NSError*)error | |
{ | |
NSLog(@".......... srcDidComplete"); | |
UIAlertView* alert; | |
if(error){ | |
alert = [[UIAlertView alloc] initWithTitle:[error.userInfo objectForKey:@"NSLocalizedDescription"] | |
message:[error.userInfo objectForKey:@"NSLocalizedRecoverySuggestion"] | |
delegate:nil | |
cancelButtonTitle:nil | |
otherButtonTitles:@"OK", nil]; | |
}else{ | |
alert = [[UIAlertView alloc] initWithTitle:@"Complete" | |
message:nil | |
delegate:nil | |
cancelButtonTitle:nil | |
otherButtonTitles:@"OK", nil]; | |
} | |
[alert show]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment