336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.



오늘은 iOS 에서 사용 되는 기본 TTS(Text-to_Speech)에 대한 사용 설명 입니다.

잘 되어 있는 오픈소스도 많지만 기본으로 제공 되는 프레임워크를 통해 쉽게 구현 하실 수 있습니다.

TTS를 기본적으로 사용 하실려면 'AVFoundation'라는 프레임워크를 임포트 시켜 주셔야 됩니다. 

이제 Objective-C를 내려놓고 Swift를 사용 하는 시점이기 때문에 Swift를 통해 설명을 해 드리겠습니다.


밑에 코드를 보시면 AvSpeechSynthesizer를 통해 초기화를 해주시고나서

AVSpeechUtterance를 통해 TTS로 읽어줄 텍스트와 각 언어별로 지정을 해주고 rate를 통해 속도를 조절합니다. 

(저 같은 경우에는 0.4가 적당한 수치라고 느껴지는데 한번 수치를 다양한게 변경시켜서 앱 성격에 맞게 조절 해주시면 됩니다.)

AvSpeechSynthesizer로 초기화한 synthesizer의 speakUtterance 메소드를 통해 설정 해 놓은 AVSpeechUtterance 출력 시키면 됩니다.


(Swift)

1
2
3
4
5
6
7
let synthesizer = AVSpeechSynthesizer()

let utterance = AVSpeechUtterance(string: "your String")        
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
utterance.rate = 0.4
        
synthesizer.speakUtterance(utterance)
cs


(Objective-C)

1
2
3
4
5
6
7
AVSpeechSynthesizer * synthesizer = [[AVSpeechSynthesizer alloc]init];
    
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc]initWithString:@"Your String"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
utterance.rate = 0.4f;
    
[synthesizer speakUtterance:utterance];
cs


(지원 가능한 언어 목록)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Arabic (Saudi Arabia) - ar-SA
Chinese (China) - zh-CN
Chinese (Hong Kong SAR China) - zh-HK
Chinese (Taiwan) - zh-TW
Czech (Czech Republic) - cs-CZ
Danish (Denmark) - da-DK
Dutch (Belgium) - nl-BE
Dutch (Netherlands) - nl-NL
English (Australia) - en-AU
English (Ireland) - en-IE
English (South Africa) - en-ZA
English (United Kingdom) - en-GB
English (United States) - en-US
Finnish (Finland) - fi-FI
French (Canada) - fr-CA
French (France) - fr-FR
German (Germany) - de-DE
Greek (Greece) - el-GR
Hindi (India) - hi-IN
Hungarian (Hungary) - hu-HU
Indonesian (Indonesia) - id-ID
Italian (Italy) - it-IT
Japanese (Japan) - ja-JP
Korean (South Korea) - ko-KR
Norwegian (Norway) - no-NO
Polish (Poland) - pl-PL
Portuguese (Brazil) - pt-BR
Portuguese (Portugal) - pt-PT
Romanian (Romania) - ro-RO
Russian (Russia) - ru-RU
Slovak (Slovakia) - sk-SK
Spanish (Mexico) - es-MX
Spanish (Spain) - es-ES
Swedish (Sweden) - sv-SE
Thai (Thailand) - th-TH
Turkish (Turkey) - tr-TR
cs

출처 : http://susemi99.kr/981



'iOS 프로그래밍 > iOS' 카테고리의 다른 글

iOS)딕셔너리 키값 정렬 하기  (0) 2016.06.06
iOS)랜덤 함수  (0) 2016.05.26
iOS)iPhone 해상도  (0) 2016.05.09
iOS)단어 정의 사전으로 찾기  (0) 2016.05.04
iOS)App 설정으로 이동하기  (0) 2016.05.03
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.



iPhone 이 예전에는 4s/5/5s 기준으로만 개발을 하면 되었지만 작년 부터 6/6+가 추가되어 신경 써야 할 화면 크기가 늘었습니다. 

Autolayout을 쓰는 분들이라면 크게 문제가 안되겠지만 (결국 가로 세로 비율은 같습니다.) 

안쓰는 경우에는 매우 민감한 문제이기 때문입니다.

개발에서 사용되는 해상도는

  • 4/4s - 320*480
  • 5/5s - 320*568
  • 6/6s - 375*667
  • 6+/6s+ - 414*736

개발에 사용되는 해상도를 생각하시고 개발하면 나머지는 알아서 기기가 해주기 때문에 따로 설정을 안해주셔도 실제 해상도로 맞춰서 됩니다.
밑에 사진은 iPhone 2G 부터 iPhone 6+ 까지 개발 해상도 부터 실제 해상도 까지 나온 표입니다.


출처 : http://www.paintcodeapp.com/news/ultimate-guide-to-iphone-resolutions



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.



특정 단어를 영어사전 또는 기타 사전으로 찾아서 결과를 보여주는 뷰컨트롤러 입니다.

영어단어, 회화 어플리케이션에서 여러모로 쓸모가 있을꺼 같습니다.

처음 창을 띄우면 아무 것도 나타나지 않습니다. 왼쪽 하단 밑에 관리에 들어가서 해당 언어를 다운 받으면 나타납니다.


(Objective-C)

1
2
UIReferenceLibraryViewController * ViewController = [[UIReferenceLibraryViewController alloc] initWithTerm:"찾고자 하는 단어"];
[self presentModalViewController:ViewController animated:YES];
cs


(Swift)

1
2
let ViewController = UIReferenceLibraryViewController(term: "찾고자 하는 단어")  
self.presentViewController(ViewController, animated: true, completion: nil)
cs



지원되는 언어 및 사전 종류

 



옵션이라는 단어를 찾으면 이런 결과를 보여줍니다.



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.



iOS는 안드로이드와는 다르게 권한을 설치 할때 물어보는 것이 아니라 앱을 구동하면 물어서 권한을 획득합니다. 

문제는 권한을 실수로 사용자가 허용안함으로 했을때, 기능상 문제가 생길수 있는데 이럴때 iOS를 처음 다루거나 잘 모르시는 분들은 App이 문제가 생긴줄 알 수 있습니다. 

그럴 때는 알트창을 띄어 충분히 설명을 하고 설정에서 App에 대한 권한을 고칠 수 있는 곳으로 이동 시키면 될꺼 같습니다. 

생각보다 간단합니다. 이동을 원하는 곳에서 실행 시켜 주시면 됩니다.


(Objective-C)

1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@앱번들ID", UIApplicationOpenSettingsURLString]]];
cs


(Swift)

1
UIApplication.sharedApplication().openURL(NSURL(string: "\(UIApplicationOpenSettingsURLString)프로젝트앱번들ID")!)
cs



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


위젯에서 버튼 또는 특정 이벤트를 통해 앱으로 연결 방법 입니다.

일단 info.plist에 사진과 같이 URL types을 추가해 주셔야 됩니다.

URL identifier은 앱 고유 아이디인 Bundle ID를 적고, URL  Schemes에 앱 이름을 적어 주시면 됩니다.

밑에 코드에 앱네임을 적어 주시고 원하는 위치에 코드를 적용 시켜 주시면 됩니다.

(Objective-C)

1
2
NSURL * url = [NSURL URLWithString:@"AppName://"];
[self.extensionContext openURL:url completionHandler:nil];
cs


(Swift)

1
2
let url = NSURL(string: "AppName://")
extensionContext?.openURL(url!, completionHandler: nil)

cs



336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

이미지에 원하는 색으로 색칠을 해주는 코드입니다.

같은 아이콘이지만 여러가지 색으로 바꿔줘야 할때 유용 할 것 같습니다.


(Objective-C 코드)

1
2
3
4
5
6
7
8
9
10
UIImage *image = [UIImage imageNamed:@“your_img_name”];
CGRect rect = CGRectMake(00, image.size.width, image.size.height);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, image.scale);
CGContextRef c = UIGraphicsGetCurrentContext();
[image drawInRect:rect];
CGContextSetFillColorWithColor(c, [UIColor blackColor].CGColor);
CGContextSetBlendMode(c, kCGBlendModeSourceAtop);
CGContextFillRect(c, rect);
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cs


(Swift 코드)

1
2
3
4
5
6
7
8
9
10
let image = UIImage(named: "your_img_name")
let rect = CGRectMake(00, image!.size.width, image!.size.height)
UIGraphicsBeginImageContextWithOptions(rect.size, false, image!.scale)
let c : CGContextRef = UIGraphicsGetCurrentContext()!
image?.drawInRect(rect)
CGContextSetFillColorWithColor(c, UIColor.blackColor().CGColor)
CGContextSetBlendMode(c, CGBlendMode.SourceAtop)
CGContextFillRect(c, rect)
let resultImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
cs


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

앱을 만들때 세로모드만 사용하여 가로모드를 막아야 할 경우 필요한 코드 입니다.

가르모드가 필요없는 뷰컨트롤러에 넣어 주면 적용됩니다.


(Objective-C 코드)

1
2
3
4
- (NSUInteger) supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait; //세로 화면만 허용
}
cs

UIInterfaceOrientation 속성입니다.

UIInterfaceOrientationMaskPortrait //세로 화면만 허용

UIInterfaceOrientationMaskAll //전체 화면 허용

UIInterfaceOrientationMaskPortraitUpsideDown //거꾸로만 허용

UIInterfaceOrientationMaskLandscape; //가로화면만 허용


(Swift 코드)

1
2
3
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.Portrait
}
cs

UIInterfaceOrientation 속성입니다.

UIInterfaceOrientationMask.Portrait //세로 화면만 허용

UIInterfaceOrientationMask.All //전체 화면 허용

UIInterfaceOrientationMask.PortraitUpsideDown //거꾸로만 허용

UIInterfaceOrientationMask.Landscape //가로화면만 허용

336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

위젯을 만들때 왼쪽 여백 조금 남습니다.

디자인상 왼쪽 여백 필요 하시면 그냥 쓰시면 되지만 또 디자인상 불필요할때도 있습니다.

그 왼쪽 여백을 없애주는 코드 입니다. 그냥 추가만 해주시면 되요!


(Objective-C 코드)

1
2
3
-(UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets {
    return UIEdgeInsetsZero
}


cs

(Swift 코드)

1
2
3
func widgetMarginInsetsForProposedMarginInsets(defaultMarginInsets: UIEdgeInsets) -> UIEdgeInsets {
    return UIEdgeInsetsZero
}
cs


336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

최상단에 있는 rootViewController를 가지고 오는 코드입니다.

(Objective-C 코드)

1
UIViewController * viewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
cs

(Swift 코드)

1
let viewController: UIViewController = UIApplication.sharedApplication().delegate!.window!!.rootViewController!
cs


+ Recent posts