Skip to content

Commit ad0ffd3

Browse files
sumengsumeng
authored andcommitted
UIMessageInputView添加录音功能
1 parent a553d7f commit ad0ffd3

23 files changed

+1927
-9
lines changed

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,15 @@
466466
4EFE8DAF1B3960E6004B7559 /* logo_coding_top@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4EFE8DAE1B3960E6004B7559 /* logo_coding_top@2x.png */; };
467467
4EFE8DB91B3A5727004B7559 /* Launch Screen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4EFE8DB81B3A5727004B7559 /* Launch Screen.xib */; };
468468
68D9A2AD062641F5BCA573C5 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B024F2227BD4152BC7C9A7A /* libPods.a */; };
469+
7EB02FCE1B6CF5D500D2166C /* UIMessageInputView_Voice.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EB02FCD1B6CF5D500D2166C /* UIMessageInputView_Voice.m */; };
470+
7EB02FE41B6D0F3E00D2166C /* amrFileCodec.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EB02FD21B6D0F3E00D2166C /* amrFileCodec.m */; };
471+
7EB02FE51B6D0F3E00D2166C /* AudioAmrUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EB02FD41B6D0F3E00D2166C /* AudioAmrUtil.m */; };
472+
7EB02FE61B6D0F3E00D2166C /* AudioManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EB02FD61B6D0F3E00D2166C /* AudioManager.m */; };
473+
7EB02FE81B6D0F3E00D2166C /* libopencore-amrnb.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7EB02FE21B6D0F3E00D2166C /* libopencore-amrnb.a */; };
474+
7EB02FE91B6D0F3E00D2166C /* libopencore-amrwb.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7EB02FE31B6D0F3E00D2166C /* libopencore-amrwb.a */; };
475+
7EB02FF11B6D111300D2166C /* AudioPlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EB02FEC1B6D111300D2166C /* AudioPlayView.m */; };
476+
7EB02FF21B6D111300D2166C /* BubblePlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EB02FEE1B6D111300D2166C /* BubblePlayView.m */; };
477+
7EB02FF31B6D111300D2166C /* AudioRecordView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EB02FF01B6D111300D2166C /* AudioRecordView.m */; };
469478
8E03D4A219F695FE0092F8C8 /* libMobClickLibrary.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E03D49F19F695FE0092F8C8 /* libMobClickLibrary.a */; };
470479
8E03D4A419F696970092F8C8 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 8E03D4A319F696970092F8C8 /* libz.dylib */; };
471480
8E1C3DEA19E7D58A00EF3032 /* AbstractActionSheetPicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E1C3DDA19E7D58A00EF3032 /* AbstractActionSheetPicker.m */; };
@@ -1487,6 +1496,26 @@
14871496
4EFE8DAB1B394A0D004B7559 /* file_changeType_RENAME@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "file_changeType_RENAME@2x.png"; sourceTree = "<group>"; };
14881497
4EFE8DAE1B3960E6004B7559 /* logo_coding_top@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "logo_coding_top@2x.png"; sourceTree = "<group>"; };
14891498
4EFE8DB81B3A5727004B7559 /* Launch Screen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "Launch Screen.xib"; sourceTree = "<group>"; };
1499+
7EB02FCC1B6CF5D500D2166C /* UIMessageInputView_Voice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIMessageInputView_Voice.h; sourceTree = "<group>"; };
1500+
7EB02FCD1B6CF5D500D2166C /* UIMessageInputView_Voice.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIMessageInputView_Voice.m; sourceTree = "<group>"; };
1501+
7EB02FD11B6D0F3E00D2166C /* amrFileCodec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amrFileCodec.h; sourceTree = "<group>"; };
1502+
7EB02FD21B6D0F3E00D2166C /* amrFileCodec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = amrFileCodec.m; sourceTree = "<group>"; };
1503+
7EB02FD31B6D0F3E00D2166C /* AudioAmrUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioAmrUtil.h; sourceTree = "<group>"; };
1504+
7EB02FD41B6D0F3E00D2166C /* AudioAmrUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioAmrUtil.m; sourceTree = "<group>"; };
1505+
7EB02FD51B6D0F3E00D2166C /* AudioManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioManager.h; sourceTree = "<group>"; };
1506+
7EB02FD61B6D0F3E00D2166C /* AudioManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioManager.m; sourceTree = "<group>"; };
1507+
7EB02FDC1B6D0F3E00D2166C /* interf_dec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = interf_dec.h; sourceTree = "<group>"; };
1508+
7EB02FDD1B6D0F3E00D2166C /* interf_enc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = interf_enc.h; sourceTree = "<group>"; };
1509+
7EB02FDF1B6D0F3E00D2166C /* dec_if.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dec_if.h; sourceTree = "<group>"; };
1510+
7EB02FE01B6D0F3E00D2166C /* if_rom.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = if_rom.h; sourceTree = "<group>"; };
1511+
7EB02FE21B6D0F3E00D2166C /* libopencore-amrnb.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libopencore-amrnb.a"; sourceTree = "<group>"; };
1512+
7EB02FE31B6D0F3E00D2166C /* libopencore-amrwb.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libopencore-amrwb.a"; sourceTree = "<group>"; };
1513+
7EB02FEB1B6D111300D2166C /* AudioPlayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioPlayView.h; sourceTree = "<group>"; };
1514+
7EB02FEC1B6D111300D2166C /* AudioPlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioPlayView.m; sourceTree = "<group>"; };
1515+
7EB02FED1B6D111300D2166C /* BubblePlayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BubblePlayView.h; sourceTree = "<group>"; };
1516+
7EB02FEE1B6D111300D2166C /* BubblePlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BubblePlayView.m; sourceTree = "<group>"; };
1517+
7EB02FEF1B6D111300D2166C /* AudioRecordView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioRecordView.h; sourceTree = "<group>"; };
1518+
7EB02FF01B6D111300D2166C /* AudioRecordView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioRecordView.m; sourceTree = "<group>"; };
14901519
8B18B0211092D3903D031B13 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
14911520
8E03D49F19F695FE0092F8C8 /* libMobClickLibrary.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libMobClickLibrary.a; sourceTree = "<group>"; };
14921521
8E03D4A019F695FE0092F8C8 /* MobClick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MobClick.h; sourceTree = "<group>"; };
@@ -1983,10 +2012,12 @@
19832012
8E03D4A419F696970092F8C8 /* libz.dylib in Frameworks */,
19842013
8EF5E74519C68CC7009346D5 /* libicucore.dylib in Frameworks */,
19852014
4EDD8F511A36F42200E9E232 /* libXG-SDK.a in Frameworks */,
2015+
7EB02FE81B6D0F3E00D2166C /* libopencore-amrnb.a in Frameworks */,
19862016
8E61D27B19C028CC00C00414 /* AssetsLibrary.framework in Frameworks */,
19872017
8EBAA73F19B9695600829E2A /* libxml2.2.dylib in Frameworks */,
19882018
8E9866C2198E416C00ABFFA0 /* CoreText.framework in Frameworks */,
19892019
8E477016198770E700997D05 /* CoreGraphics.framework in Frameworks */,
2020+
7EB02FE91B6D0F3E00D2166C /* libopencore-amrwb.a in Frameworks */,
19902021
8E47701A198770E700997D05 /* CoreData.framework in Frameworks */,
19912022
8E477018198770E700997D05 /* UIKit.framework in Frameworks */,
19922023
8E477014198770E700997D05 /* Foundation.framework in Frameworks */,
@@ -2592,6 +2623,8 @@
25922623
4EABD2591AD3CB4A005E515F /* UIMessageInputView_CCell.m */,
25932624
4EABD25B1AD3CBB9005E515F /* UIMessageInputView_Media.h */,
25942625
4EABD25C1AD3CBB9005E515F /* UIMessageInputView_Media.m */,
2626+
7EB02FCC1B6CF5D500D2166C /* UIMessageInputView_Voice.h */,
2627+
7EB02FCD1B6CF5D500D2166C /* UIMessageInputView_Voice.m */,
25952628
);
25962629
path = UIMessageInputView;
25972630
sourceTree = "<group>";
@@ -2825,6 +2858,78 @@
28252858
name = Pods;
28262859
sourceTree = "<group>";
28272860
};
2861+
7EB02FD01B6D0F3E00D2166C /* Audio */ = {
2862+
isa = PBXGroup;
2863+
children = (
2864+
7EB02FD71B6D0F3E00D2166C /* opencore-amr-iOS */,
2865+
7EB02FD11B6D0F3E00D2166C /* amrFileCodec.h */,
2866+
7EB02FD21B6D0F3E00D2166C /* amrFileCodec.m */,
2867+
7EB02FD31B6D0F3E00D2166C /* AudioAmrUtil.h */,
2868+
7EB02FD41B6D0F3E00D2166C /* AudioAmrUtil.m */,
2869+
7EB02FD51B6D0F3E00D2166C /* AudioManager.h */,
2870+
7EB02FD61B6D0F3E00D2166C /* AudioManager.m */,
2871+
);
2872+
path = Audio;
2873+
sourceTree = "<group>";
2874+
};
2875+
7EB02FD71B6D0F3E00D2166C /* opencore-amr-iOS */ = {
2876+
isa = PBXGroup;
2877+
children = (
2878+
7EB02FDA1B6D0F3E00D2166C /* include */,
2879+
7EB02FE11B6D0F3E00D2166C /* lib */,
2880+
);
2881+
path = "opencore-amr-iOS";
2882+
sourceTree = "<group>";
2883+
};
2884+
7EB02FDA1B6D0F3E00D2166C /* include */ = {
2885+
isa = PBXGroup;
2886+
children = (
2887+
7EB02FDB1B6D0F3E00D2166C /* opencore-amrnb */,
2888+
7EB02FDE1B6D0F3E00D2166C /* opencore-amrwb */,
2889+
);
2890+
path = include;
2891+
sourceTree = "<group>";
2892+
};
2893+
7EB02FDB1B6D0F3E00D2166C /* opencore-amrnb */ = {
2894+
isa = PBXGroup;
2895+
children = (
2896+
7EB02FDC1B6D0F3E00D2166C /* interf_dec.h */,
2897+
7EB02FDD1B6D0F3E00D2166C /* interf_enc.h */,
2898+
);
2899+
path = "opencore-amrnb";
2900+
sourceTree = "<group>";
2901+
};
2902+
7EB02FDE1B6D0F3E00D2166C /* opencore-amrwb */ = {
2903+
isa = PBXGroup;
2904+
children = (
2905+
7EB02FDF1B6D0F3E00D2166C /* dec_if.h */,
2906+
7EB02FE01B6D0F3E00D2166C /* if_rom.h */,
2907+
);
2908+
path = "opencore-amrwb";
2909+
sourceTree = "<group>";
2910+
};
2911+
7EB02FE11B6D0F3E00D2166C /* lib */ = {
2912+
isa = PBXGroup;
2913+
children = (
2914+
7EB02FE21B6D0F3E00D2166C /* libopencore-amrnb.a */,
2915+
7EB02FE31B6D0F3E00D2166C /* libopencore-amrwb.a */,
2916+
);
2917+
path = lib;
2918+
sourceTree = "<group>";
2919+
};
2920+
7EB02FEA1B6D10F700D2166C /* AudioView */ = {
2921+
isa = PBXGroup;
2922+
children = (
2923+
7EB02FEB1B6D111300D2166C /* AudioPlayView.h */,
2924+
7EB02FEC1B6D111300D2166C /* AudioPlayView.m */,
2925+
7EB02FED1B6D111300D2166C /* BubblePlayView.h */,
2926+
7EB02FEE1B6D111300D2166C /* BubblePlayView.m */,
2927+
7EB02FEF1B6D111300D2166C /* AudioRecordView.h */,
2928+
7EB02FF01B6D111300D2166C /* AudioRecordView.m */,
2929+
);
2930+
path = AudioView;
2931+
sourceTree = "<group>";
2932+
};
28282933
8E03D49E19F695FE0092F8C8 /* UMENG */ = {
28292934
isa = PBXGroup;
28302935
children = (
@@ -3590,6 +3695,7 @@
35903695
8EA6CFFD19E240C40076D59C /* Common */,
35913696
8EA6D01019E240C40076D59C /* ObjcRuntime */,
35923697
4ECE8AAF1A3943E80021E29C /* OC_Category */,
3698+
7EB02FD01B6D0F3E00D2166C /* Audio */,
35933699
);
35943700
path = Util;
35953701
sourceTree = "<group>";
@@ -3727,6 +3833,7 @@
37273833
8EF6436319FF7E2900F7EEB0 /* Cell */,
37283834
8EF6435419FF7E2900F7EEB0 /* CCell */,
37293835
4EABD2511AD3CA7E005E515F /* UIMessageInputView */,
3836+
7EB02FEA1B6D10F700D2166C /* AudioView */,
37303837
3A38784A1AE36EF00078D5DE /* TopicListView.h */,
37313838
3A38784B1AE36EF00078D5DE /* TopicListView.m */,
37323839
3A3878471AE36ED70078D5DE /* TopicListButton.h */,
@@ -4452,6 +4559,7 @@
44524559
4EA679131A1466A6001A0324 /* ProjectFiles.m in Sources */,
44534560
4EBDA87C1A6640340035ED96 /* UIActionSheet+Common.m in Sources */,
44544561
4E4D6A581B1C5DC000FD2E49 /* MRPRCommentCell.m in Sources */,
4562+
7EB02FF11B6D111300D2166C /* AudioPlayView.m in Sources */,
44554563
B94C1B6E1AC98CCE0000C271 /* NewProjectTypeViewController.m in Sources */,
44564564
4E96E7BB1A1B25D40037C098 /* DirectoryWatcher.m in Sources */,
44574565
4ED673221A8E0ECC00DF2D1A /* SVWebViewControllerActivityReport.m in Sources */,
@@ -4487,6 +4595,7 @@
44874595
4ED6731E1A8DD38C00DF2D1A /* ReportIllegalViewController.m in Sources */,
44884596
8EF643CE19FF7E2900F7EEB0 /* TweetDetailCell.m in Sources */,
44894597
4EABD2571AD3CAAC005E515F /* UIMessageInputView_Add.m in Sources */,
4598+
7EB02FCE1B6CF5D500D2166C /* UIMessageInputView_Voice.m in Sources */,
44904599
8E59F0E21A0098BA009A905F /* UIScrollView+SVInfiniteScrolling.m in Sources */,
44914600
4E15C7D01A26D2F000FB8DAD /* FolderToMoveViewController.m in Sources */,
44924601
4EE5481E1AE7B7CA00A92306 /* UISearchBar+Common.m in Sources */,
@@ -4527,6 +4636,7 @@
45274636
4E4D6AAF1B2047DE00FD2E49 /* CommitCommentCell.m in Sources */,
45284637
4EA7F15F1A6D192B00A046BD /* SDWebImageManager.m in Sources */,
45294638
8E64ED8519ED0CE3006E99DA /* QBImagePickerThumbnailView.m in Sources */,
4639+
7EB02FE41B6D0F3E00D2166C /* amrFileCodec.m in Sources */,
45304640
8E1C3E0D19E8DFE300EF3032 /* SettingViewController.m in Sources */,
45314641
8E1C3DEF19E7D58A00EF3032 /* ActionSheetStringPicker.m in Sources */,
45324642
8EF643B919FF7E2900F7EEB0 /* LeftImage_LRTextCell.m in Sources */,
@@ -4536,6 +4646,7 @@
45364646
0A0519E21ABA918100551B61 /* TweetSendDetailLoctionCell.m in Sources */,
45374647
4E5C06EB1AC4009100F427C5 /* CannotLoginViewController.m in Sources */,
45384648
8EA6D12819E240C40076D59C /* AppDelegate.m in Sources */,
4649+
7EB02FE51B6D0F3E00D2166C /* AudioAmrUtil.m in Sources */,
45394650
4ECE8AFF1A3946C10021E29C /* Coding_NetAPIManager.m in Sources */,
45404651
8E59F0FA1A00F3F3009A905F /* FileListFileCell.m in Sources */,
45414652
8EA6D14219E240C40076D59C /* TipsViewController.m in Sources */,
@@ -4569,6 +4680,7 @@
45694680
4E4D6A671B1C686F00FD2E49 /* AddMDCommentViewController.m in Sources */,
45704681
4ECE8AFE1A3946C10021E29C /* Coding_FileManager.m in Sources */,
45714682
4EABD2541AD3CA7E005E515F /* UIMessageInputView.m in Sources */,
4683+
7EB02FE61B6D0F3E00D2166C /* AudioManager.m in Sources */,
45724684
4E72F82D1B144778001B6CE6 /* NSMutableString+Common.m in Sources */,
45734685
4E4D6A791B1C6C7800FD2E49 /* MRPRDetailCell.m in Sources */,
45744686
8EF643CA19FF7E2900F7EEB0 /* TopicContentCell.m in Sources */,
@@ -4694,6 +4806,7 @@
46944806
4EE548211AE8DB5600A92306 /* Project.m in Sources */,
46954807
4EE1A22C1B5D02CA004284F1 /* ProjectActivityListView.m in Sources */,
46964808
4E6BA2D81A1EE6AF005FD721 /* AFHTTPRequestOperationManager.m in Sources */,
4809+
7EB02FF21B6D111300D2166C /* BubblePlayView.m in Sources */,
46974810
4ECE8AE21A3943E80021E29C /* UIColor+expanded.m in Sources */,
46984811
4EA7F15D1A6D192B00A046BD /* SDWebImageDownloader.m in Sources */,
46994812
8EA6D1B419E240C40076D59C /* HtmlMedia.m in Sources */,
@@ -4801,6 +4914,7 @@
48014914
8EA6D1FB19E240C40076D59C /* MJPhotoToolbar.m in Sources */,
48024915
8EF643CF19FF7E2900F7EEB0 /* TweetDetailCommentCell.m in Sources */,
48034916
4E4D6A8E1B1D5B9A00FD2E49 /* MRPRBaseInfo.m in Sources */,
4917+
7EB02FF31B6D111300D2166C /* AudioRecordView.m in Sources */,
48044918
4E4D6A9A1B1D893500FD2E49 /* CommitInfo.m in Sources */,
48054919
4E38CF5F1A7A28AF005536C0 /* CodeBranchTagButton.m in Sources */,
48064920
8E64ED8119ED0CE3006E99DA /* QBAssetsCollectionViewLayout.m in Sources */,
@@ -4957,6 +5071,7 @@
49575071
"$(inherited)",
49585072
"$(PROJECT_DIR)/Coding_iOS/Vendor/UMENG",
49595073
"$(PROJECT_DIR)/Coding_iOS/Vendor/XGPush",
5074+
"$(PROJECT_DIR)/Coding_iOS/Util/Audio/opencore-amr-iOS/lib",
49605075
);
49615076
PRODUCT_BUNDLE_IDENTIFIER = net.coding.CodingForiOS;
49625077
PRODUCT_NAME = Coding_iOS;
@@ -4991,6 +5106,7 @@
49915106
"$(inherited)",
49925107
"$(PROJECT_DIR)/Coding_iOS/Vendor/UMENG",
49935108
"$(PROJECT_DIR)/Coding_iOS/Vendor/XGPush",
5109+
"$(PROJECT_DIR)/Coding_iOS/Util/Audio/opencore-amr-iOS/lib",
49945110
);
49955111
PRODUCT_BUNDLE_IDENTIFIER = net.coding.CodingForiOS;
49965112
PRODUCT_NAME = Coding_iOS;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// AudioAmrUtil.h
3+
// audiodemo
4+
//
5+
// Created by sumeng on 7/28/15.
6+
// Copyright (c) 2015 sumeng. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface AudioAmrUtil : NSObject
12+
13+
+ (NSString *)encodeWaveToAmr:(NSString *)waveFile;
14+
+ (NSString *)encodeWaveToAmr:(NSString *)waveFile
15+
nChannels:(int)nChannels
16+
nBitsPerSample:(int)nBitsPerSample;
17+
18+
+ (NSString *)decodeAmrToWave:(NSString *)amrFile;
19+
20+
+ (NSString *)convertedAmrFromWave:(NSString *)waveFile;
21+
+ (NSString *)convertedWaveFromAmr:(NSString *)amrFile;
22+
+ (BOOL)cleanup;
23+
24+
@end
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// AudioAmrUtil.m
3+
// audiodemo
4+
//
5+
// Created by sumeng on 7/28/15.
6+
// Copyright (c) 2015 sumeng. All rights reserved.
7+
//
8+
9+
#import "AudioAmrUtil.h"
10+
#import "amrFileCodec.h"
11+
12+
@implementation AudioAmrUtil
13+
14+
+ (NSString *)encodeWaveToAmr:(NSString *)waveFile {
15+
return [self encodeWaveToAmr:waveFile nChannels:1 nBitsPerSample:16];
16+
}
17+
18+
+ (NSString *)encodeWaveToAmr:(NSString *)waveFile
19+
nChannels:(int)nChannels
20+
nBitsPerSample:(int)nBitsPerSample {
21+
if (waveFile == nil) {
22+
return nil;
23+
}
24+
25+
NSString *amrFile = [[[self convertDir] stringByAppendingPathComponent:[[waveFile lastPathComponent] md5Str]] stringByAppendingPathExtension:@"amr"];
26+
if ([[NSFileManager defaultManager] fileExistsAtPath:amrFile]) {
27+
[[NSFileManager defaultManager] removeItemAtPath:amrFile error:nil];
28+
}
29+
NSTimeInterval date1 = [[NSDate date] timeIntervalSince1970];
30+
NSData *armData = EncodeWAVEToAMR([NSData dataWithContentsOfFile:waveFile], nChannels, nBitsPerSample);
31+
[armData writeToFile:amrFile atomically:YES];
32+
NSTimeInterval date2 = [[NSDate date] timeIntervalSince1970];
33+
NSLog(@"encodeWaveToAmr cost:%fs", date2-date1);
34+
return amrFile;
35+
}
36+
37+
+ (NSString *)decodeAmrToWave:(NSString *)amrFile {
38+
if (amrFile == nil) {
39+
return nil;
40+
}
41+
42+
NSString *waveFile = [[[self convertDir] stringByAppendingPathComponent:[[amrFile lastPathComponent] md5Str]] stringByAppendingPathExtension:@"wav"];
43+
if ([[NSFileManager defaultManager] fileExistsAtPath:waveFile]) {
44+
[[NSFileManager defaultManager] removeItemAtPath:waveFile error:nil];
45+
}
46+
NSTimeInterval date1 = [[NSDate date] timeIntervalSince1970];
47+
NSData *waveData = DecodeAMRToWAVE([NSData dataWithContentsOfFile:amrFile]);
48+
[waveData writeToFile:waveFile atomically:YES];
49+
NSTimeInterval date2 = [[NSDate date] timeIntervalSince1970];
50+
NSLog(@"decodeAmrToWave cost:%fs", date2-date1);
51+
return waveFile;
52+
}
53+
54+
+ (NSString *)convertedAmrFromWave:(NSString *)waveFile {
55+
NSString *amrFile = [[[self convertDir] stringByAppendingPathComponent:[[waveFile lastPathComponent] md5Str]] stringByAppendingPathExtension:@"amr"];
56+
if ([[NSFileManager defaultManager] fileExistsAtPath:amrFile]) {
57+
return amrFile;
58+
}
59+
return nil;
60+
}
61+
62+
+ (NSString *)convertedWaveFromAmr:(NSString *)amrFile {
63+
NSString *waveFile = [[[self convertDir] stringByAppendingPathComponent:[[amrFile lastPathComponent] md5Str]] stringByAppendingPathExtension:@"wav"];
64+
if ([[NSFileManager defaultManager] fileExistsAtPath:waveFile]) {
65+
return waveFile;
66+
}
67+
return nil;
68+
}
69+
70+
+ (NSString *)convertDir {
71+
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
72+
NSString *dir = [docDir stringByAppendingPathComponent:@"AudioConvert"];
73+
[[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:NO attributes:nil error:nil];
74+
return dir;
75+
}
76+
77+
+ (BOOL)cleanup {
78+
return [[NSFileManager defaultManager] removeItemAtPath:[self convertDir] error:nil];
79+
}
80+
81+
@end

0 commit comments

Comments
 (0)