Initial commit
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// NTESAudio2TextViewController.h
|
||||
// NIM
|
||||
//
|
||||
// Created by amao on 7/10/15.
|
||||
// Copyright (c) 2015 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
|
||||
|
||||
@interface NTESAudio2TextViewController : UIViewController
|
||||
|
||||
@property (nonatomic,strong) IBOutlet UIButton *cancelBtn;
|
||||
|
||||
@property (nonatomic,strong) IBOutlet UIView *errorTipView;
|
||||
|
||||
@property (nonatomic,copy) void (^completeHandler)(void) ;
|
||||
|
||||
- (instancetype)initWithMessage:(NIMMessage *)message;
|
||||
|
||||
@end
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// NTESAudio2TextViewController.m
|
||||
// NIM
|
||||
//
|
||||
// Created by amao on 7/10/15.
|
||||
// Copyright (c) 2015 Netease. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NTESAudio2TextViewController.h"
|
||||
#import "Toast+UIView.h"
|
||||
#import "SVProgressHUD.h"
|
||||
#import "UIView+NTES.h"
|
||||
#import "IfishSessionViewController.h"
|
||||
//#import "NTESMainTabController.h"
|
||||
|
||||
@interface NTESAudio2TextViewController ()
|
||||
@property (weak, nonatomic) IBOutlet UITextView *textView;
|
||||
@property (strong, nonatomic) NIMAudioToTextOption *option;
|
||||
@property (strong, nonatomic) NIMMessage *message;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NTESAudio2TextViewController
|
||||
|
||||
- (instancetype)initWithMessage:(NIMMessage *)message
|
||||
{
|
||||
if (self = [super initWithNibName:@"NTESAudio2TextViewController"
|
||||
bundle:nil])
|
||||
{
|
||||
NIMAudioToTextOption *option = [[NIMAudioToTextOption alloc] init];
|
||||
option.url = [(NIMAudioObject *)message.messageObject url];
|
||||
option.filepath = [(NIMAudioObject *)message.messageObject path];
|
||||
_option = option;
|
||||
_message = message;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[SVProgressHUD showWithStatus:@"正在转换"];
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
|
||||
[self.textView addGestureRecognizer:tap];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[[NIMSDK sharedSDK] mediaManager] transAudioToText:_option
|
||||
result:^(NSError *error, NSString *text) {
|
||||
[SVProgressHUD dismiss];
|
||||
weakSelf.cancelBtn.hidden = YES;
|
||||
[weakSelf show:error
|
||||
text:text];
|
||||
if (!error) {
|
||||
weakSelf.message.isPlayed = YES;
|
||||
}else{
|
||||
NSLog(@"audio 2 text error, %@",error);
|
||||
[weakSelf.textView removeFromSuperview];
|
||||
[weakSelf.view addSubview:weakSelf.errorTipView];
|
||||
}
|
||||
}];
|
||||
[_textView setEditable:NO];
|
||||
}
|
||||
|
||||
|
||||
- (void)viewDidLayoutSubviews{
|
||||
CGRect rect = CGRectApplyAffineTransform(self.view.frame, self.view.transform);
|
||||
self.errorTipView.top = rect.size.height * .33f;
|
||||
self.errorTipView.centerX = rect.size.width * .5f;
|
||||
}
|
||||
|
||||
|
||||
- (void)show:(NSError *)error
|
||||
text:(NSString *)text
|
||||
{
|
||||
if (error) {
|
||||
[self.view makeToast:NSLocalizedString(@"转换失败", nil)
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
_textView.text = text;
|
||||
[_textView sizeToFit];
|
||||
if (self.textView.height + self.textView.top > self.view.height) {
|
||||
self.textView.height = self.view.height - self.textView.top;
|
||||
self.textView.scrollEnabled = YES;
|
||||
}else{
|
||||
self.textView.scrollEnabled = NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
[super touchesBegan:touches withEvent:event];
|
||||
[self hide];
|
||||
}
|
||||
|
||||
- (void)hide{
|
||||
[SVProgressHUD dismiss];
|
||||
void (^handler)(void) = self.completeHandler;
|
||||
[self dismissViewControllerAnimated:NO
|
||||
completion:^{
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (IBAction)cancelTrans:(id)sender{
|
||||
[SVProgressHUD dismiss];
|
||||
[self dismissViewControllerAnimated:NO
|
||||
completion:nil];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate{
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="NTESAudio2TextViewController">
|
||||
<connections>
|
||||
<outlet property="cancelBtn" destination="sK0-gU-oAU" id="aYa-Nk-LF1"/>
|
||||
<outlet property="errorTipView" destination="gwT-eL-EMw" id="cQ2-zF-VkE"/>
|
||||
<outlet property="textView" destination="Bk1-92-HYJ" id="QbI-u3-znJ"/>
|
||||
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
|
||||
</connections>
|
||||
</placeholder>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="center" id="Bk1-92-HYJ">
|
||||
<rect key="frame" x="20" y="70" width="280" height="456"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<color key="textColor" red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="34"/>
|
||||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
||||
</textView>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="sK0-gU-oAU">
|
||||
<rect key="frame" x="10" y="512" width="300" height="40"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<state key="normal" title="取消" backgroundImage="icon_cell_red_normal">
|
||||
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</state>
|
||||
<state key="highlighted" backgroundImage="icon_cell_red_pressed"/>
|
||||
<connections>
|
||||
<action selector="cancelTrans:" destination="-1" eventType="touchUpInside" id="Kwx-G3-9w6"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
|
||||
<point key="canvasLocation" x="488" y="274"/>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" id="gwT-eL-EMw">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="155"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="语音转化失败" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="bGw-4c-Bih">
|
||||
<rect key="frame" x="110" y="134" width="102" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<color key="textColor" red="0.40000000000000002" green="0.40000000000000002" blue="0.40000000000000002" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="icon_error" id="QHy-SH-Ywn">
|
||||
<rect key="frame" x="102" y="0.0" width="119" height="119"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<point key="canvasLocation" x="488" y="680.5"/>
|
||||
</view>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="icon_cell_red_normal" width="304" height="45"/>
|
||||
<image name="icon_cell_red_pressed" width="304" height="45"/>
|
||||
<image name="icon_error" width="119" height="119"/>
|
||||
</resources>
|
||||
<simulatedMetricsContainer key="defaultSimulatedMetrics">
|
||||
<simulatedStatusBarMetrics key="statusBar"/>
|
||||
<simulatedOrientationMetrics key="orientation"/>
|
||||
<simulatedScreenMetrics key="destination" type="retina4"/>
|
||||
</simulatedMetricsContainer>
|
||||
</document>
|
||||
Reference in New Issue
Block a user