summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2018-04-23 16:39:32 -0400
committerNicoleYarroch <nicole@livio.io>2018-04-23 16:39:32 -0400
commitec489d3e2893df4a478e2ff42ff42e47d9190546 (patch)
treef94a8b4445db9ce960f7d170250b6b6461bc7f0e
parentdaf9e8d8e99d6b20b38c7d3a47ac463b0a71c4af (diff)
downloadsdl_ios-ec489d3e2893df4a478e2ff42ff42e47d9190546.tar.gz
Audio recording added to Obj-C app
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj10
-rw-r--r--SmartDeviceLink_Example/AppDelegate.m1
-rw-r--r--SmartDeviceLink_Example/AudioManager.h25
-rw-r--r--SmartDeviceLink_Example/AudioManager.m128
-rw-r--r--SmartDeviceLink_Example/AudioManager.swift59
-rw-r--r--SmartDeviceLink_Example/Classes/ProxyManager.h2
-rw-r--r--SmartDeviceLink_Example/Classes/ProxyManager.m32
-rw-r--r--SmartDeviceLink_Example/Enum+SDLAudioRecordingState.swift14
8 files changed, 229 insertions, 42 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index 1ce843d5f..67e3cd696 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -1050,6 +1050,8 @@
5DEF69611FD6FB75004B8C2F /* SDLAudioStreamManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DEF69601FD6FB75004B8C2F /* SDLAudioStreamManagerSpec.m */; };
5DEF69661FD6FEF7004B8C2F /* SDLStreamingAudioManagerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DEF69651FD6FEF7004B8C2F /* SDLStreamingAudioManagerMock.m */; };
5DFFB9151BD7C89700DB3F04 /* SDLConnectionManagerType.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DFFB9141BD7C89700DB3F04 /* SDLConnectionManagerType.h */; };
+ 8803A0AA208E281E009FDC02 /* Enum+SDLAudioRecordingState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8803A0A7208E27E6009FDC02 /* Enum+SDLAudioRecordingState.swift */; };
+ 8803A0AF208E2A3A009FDC02 /* AudioManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8803A0AC208E2907009FDC02 /* AudioManager.m */; };
880E35B42088F75A00181259 /* SDLSystemCapabilityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 880E35B22088F75A00181259 /* SDLSystemCapabilityManager.m */; };
880E35B52088F75A00181259 /* SDLSystemCapabilityManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 880E35B32088F75A00181259 /* SDLSystemCapabilityManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
880E35B82088F78E00181259 /* SDLSystemCapabilityManagerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 880E35B72088F78E00181259 /* SDLSystemCapabilityManagerSpec.m */; };
@@ -2376,6 +2378,9 @@
5DEF69651FD6FEF7004B8C2F /* SDLStreamingAudioManagerMock.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDLStreamingAudioManagerMock.m; sourceTree = "<group>"; };
5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLURLSessionSpec.m; path = "UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m"; sourceTree = "<group>"; };
5DFFB9141BD7C89700DB3F04 /* SDLConnectionManagerType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLConnectionManagerType.h; sourceTree = "<group>"; };
+ 8803A0A7208E27E6009FDC02 /* Enum+SDLAudioRecordingState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Enum+SDLAudioRecordingState.swift"; sourceTree = "<group>"; };
+ 8803A0AB208E2907009FDC02 /* AudioManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioManager.h; sourceTree = "<group>"; };
+ 8803A0AC208E2907009FDC02 /* AudioManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AudioManager.m; sourceTree = "<group>"; };
880E35B22088F75A00181259 /* SDLSystemCapabilityManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLSystemCapabilityManager.m; sourceTree = "<group>"; };
880E35B32088F75A00181259 /* SDLSystemCapabilityManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLSystemCapabilityManager.h; sourceTree = "<group>"; };
880E35B72088F78E00181259 /* SDLSystemCapabilityManagerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLSystemCapabilityManagerSpec.m; sourceTree = "<group>"; };
@@ -3283,6 +3288,8 @@
children = (
5D48329F1A92868E00252386 /* ProxyManager.h */,
5D4832A01A92868E00252386 /* ProxyManager.m */,
+ 8803A0AB208E2907009FDC02 /* AudioManager.h */,
+ 8803A0AC208E2907009FDC02 /* AudioManager.m */,
);
name = SDL;
sourceTree = "<group>";
@@ -4844,6 +4851,7 @@
885D259A207D107A00BD6EE7 /* Enum+SDLProxyState.swift */,
885D259D207D144E00BD6EE7 /* Enum+SDLHMILevelFirstState.swift */,
8863B59E207D4308002D6459 /* Enum+SDLConnectionType.swift */,
+ 8803A0A7208E27E6009FDC02 /* Enum+SDLAudioRecordingState.swift */,
88DFB051207F8DF50079D19D /* Protocol+ProxyManagerDelegate.swift */,
);
name = Utilities;
@@ -5648,6 +5656,7 @@
files = (
5D4832A51A94F90D00252386 /* ConnectionTransitionContext.m in Sources */,
5D0218FC1A8E7E1700D1BF62 /* ConnectionContainerViewController.m in Sources */,
+ 8803A0AF208E2A3A009FDC02 /* AudioManager.m in Sources */,
5D0218FF1A8E9E0D00D1BF62 /* ConnectionIAPTableViewController.m in Sources */,
5D48329D1A8EA33D00252386 /* Preferences.m in Sources */,
5D59350F1A855EB300687FB9 /* AppDelegate.m in Sources */,
@@ -6409,6 +6418,7 @@
88DFB055207F96EE0079D19D /* AlertManager.swift in Sources */,
888D178F207E7F42008E9F8F /* ButtonManager.swift in Sources */,
88A0AA5E207CFE740075132C /* ConnectionTCPTableViewController.swift in Sources */,
+ 8803A0AA208E281E009FDC02 /* Enum+SDLAudioRecordingState.swift in Sources */,
885D259C207D111200BD6EE7 /* Enum+SDLProxyState.swift in Sources */,
88DFB053207F8E100079D19D /* Protocol+ProxyManagerDelegate.swift in Sources */,
88B849C820812442002A034D /* VehicleDataManager.swift in Sources */,
diff --git a/SmartDeviceLink_Example/AppDelegate.m b/SmartDeviceLink_Example/AppDelegate.m
index 1ceb6f765..b8bb1f58b 100644
--- a/SmartDeviceLink_Example/AppDelegate.m
+++ b/SmartDeviceLink_Example/AppDelegate.m
@@ -18,6 +18,7 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ [ProxyManager.sharedManager startIAP];
return YES;
}
diff --git a/SmartDeviceLink_Example/AudioManager.h b/SmartDeviceLink_Example/AudioManager.h
new file mode 100644
index 000000000..5e54cff1d
--- /dev/null
+++ b/SmartDeviceLink_Example/AudioManager.h
@@ -0,0 +1,25 @@
+//
+// AudioManager.h
+// SmartDeviceLink
+//
+// Created by Nicole on 4/23/18.
+// Copyright © 2018 smartdevicelink. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@class SDLManager;
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface AudioManager : NSObject
+
+- (instancetype)init NS_UNAVAILABLE;
+- (instancetype)initWithManager:(SDLManager *)manager;
+
+- (void)startRecording;
+- (void)stopRecording;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink_Example/AudioManager.m b/SmartDeviceLink_Example/AudioManager.m
new file mode 100644
index 000000000..48d057bbd
--- /dev/null
+++ b/SmartDeviceLink_Example/AudioManager.m
@@ -0,0 +1,128 @@
+//
+// AudioManager.m
+// SmartDeviceLink
+//
+// Created by Nicole on 4/23/18.
+// Copyright © 2018 smartdevicelink. All rights reserved.
+//
+
+#import "AudioManager.h"
+#import "SmartDeviceLink.h"
+#import <AVFoundation/AVFoundation.h>
+
+typedef NS_ENUM(NSUInteger, AudioRecordingState) {
+ AudioRecordingStateListening,
+ AudioRecordingStateNotListening
+};
+
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface AudioManager ()
+
+@property (strong, nonatomic) SDLManager *sdlManager;
+@property (strong, nonatomic, nullable) NSMutableData *audioData;
+@property (assign, nonatomic) AudioRecordingState audioRecordingState;
+
+@property (nonatomic, copy, nullable) SDLResponseHandler audioPassThruEndedHandler;
+@property (nonatomic, copy, nullable) void (^audioDataReceivedHandler)(NSData *__nullable audioData);
+
+@end
+
+
+@implementation AudioManager
+
+#pragma mark - Lifecycle
+
+- (instancetype)initWithManager:(SDLManager *)manager {
+ self = [super init];
+ if (!self) {
+ return nil;
+ }
+
+ _sdlManager = manager;
+ _audioData = [NSMutableData data];
+ _audioRecordingState = AudioRecordingStateNotListening;
+
+ return self;
+}
+
+- (void)startRecording {
+ if (self.audioRecordingState == AudioRecordingStateListening) { return; }
+
+ UInt32 recordingDurationInMilliseconds = 5000;
+ SDLPerformAudioPassThru *performAudioPassThru = [[SDLPerformAudioPassThru alloc] initWithInitialPrompt:@"Starting sound recording" audioPassThruDisplayText1:@"Say Something" audioPassThruDisplayText2:[NSString stringWithFormat:@"Recording for %d seconds", (recordingDurationInMilliseconds / 1000)] samplingRate:SDLSamplingRate16KHZ bitsPerSample:SDLBitsPerSample16Bit audioType:SDLAudioTypePCM maxDuration:recordingDurationInMilliseconds muteAudio:true audioDataHandler:self.audioDataReceivedHandler];
+
+ [self.sdlManager sendRequest:performAudioPassThru withResponseHandler:self.audioPassThruEndedHandler];
+}
+
+- (void)stopRecording {
+ self.audioRecordingState = AudioRecordingStateNotListening;
+ self.audioData = [NSMutableData data];
+}
+
+
+#pragma mark - Audio Pass Thru Notifications
+
+- (nullable void (^)(NSData * _Nullable))audioDataReceivedHandler {
+ if (!_audioPassThruEndedHandler) {
+ __weak typeof(self) weakSelf = self;
+ self.audioDataReceivedHandler = ^(NSData * _Nullable audioData) {
+ if (audioData.length == 0) { return; }
+ if (weakSelf.audioRecordingState == AudioRecordingStateNotListening) {
+ weakSelf.audioData = [NSMutableData data];
+ weakSelf.audioRecordingState = AudioRecordingStateListening;
+ }
+ [weakSelf.audioData appendData:audioData];
+ };
+ }
+
+ return _audioDataReceivedHandler;
+}
+
+- (nullable SDLResponseHandler)audioPassThruEndedHandler {
+ if (!_audioPassThruEndedHandler) {
+ __weak typeof(self) weakSelf = self;
+ self.audioPassThruEndedHandler = ^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
+ if (response == nil) { return; }
+ weakSelf.audioRecordingState = AudioRecordingStateNotListening;
+
+ SDLResult resultCode = response.resultCode;
+ if ([resultCode isEqualToEnum:SDLResultSuccess]) {
+ // The `PerformAudioPassThru` timed out or the "Done" button was pressed in the pop-up.
+ if (weakSelf.audioData.length == 0) {
+ [weakSelf.sdlManager sendRequest: [[SDLAlert alloc] initWithAlertText1:@"No audio recorded" alertText2:nil duration:5000]];
+ } else {
+ AVAudioPCMBuffer *pcmBuffer = [weakSelf sdlex_convertDataToPCMFormattedAudio:weakSelf.audioData];
+ [weakSelf.sdlManager sendRequest: [[SDLAlert alloc] initWithAlertText1:@"Audio recorded!" alertText2:[NSString stringWithFormat:@"%@", pcmBuffer] duration:5000]];
+ }
+ } else if ([resultCode isEqualToEnum:SDLResultAborted]) {
+ // The "Cancel" button was pressed in the pop-up. Ignore this audio pass thru.
+ weakSelf.audioData = [NSMutableData data];
+ [weakSelf.sdlManager sendRequest: [[SDLAlert alloc] initWithAlertText1:@"Recording canceled" alertText2:nil duration:5000]];
+ } else {
+ weakSelf.audioData = [NSMutableData data];
+ [weakSelf.sdlManager sendRequest: [[SDLAlert alloc] initWithAlertText1:@"Recording unsuccessful" alertText2:nil duration:5000]];
+ }
+ };
+ }
+
+ return _audioPassThruEndedHandler;
+}
+
+#pragma mark - Audio Data Conversion
+
+- (AVAudioPCMBuffer *)sdlex_convertDataToPCMFormattedAudio:(NSMutableData *)data {
+ AVAudioFormat *audioFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatInt16 sampleRate:16000 channels:1 interleaved:NO];
+ UInt32 numberOfFrames = (UInt32)data.length / audioFormat.streamDescription->mBytesPerFrame;
+ AVAudioPCMBuffer *buffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:audioFormat frameCapacity:numberOfFrames];
+ buffer.frameLength = numberOfFrames;
+
+ memcpy(buffer.int16ChannelData[0], data.bytes, data.length);
+
+ return buffer;
+}
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink_Example/AudioManager.swift b/SmartDeviceLink_Example/AudioManager.swift
index a7dcae75c..9d5dac470 100644
--- a/SmartDeviceLink_Example/AudioManager.swift
+++ b/SmartDeviceLink_Example/AudioManager.swift
@@ -11,24 +11,18 @@ import AVFoundation
import SmartDeviceLink
import SmartDeviceLinkSwift
-typealias audioRecordingHandler = ((AudioRecordingState) -> Void)
-
-enum AudioRecordingState {
- case listening, notListening
-}
+typealias audioRecordingHandler = ((SDLAudioRecordingState) -> Void)
class AudioManager: NSObject {
fileprivate let sdlManager: SDLManager!
fileprivate var audioData: Data?
- fileprivate var audioRecordingState: AudioRecordingState
+ fileprivate var audioRecordingState: SDLAudioRecordingState
init(sdlManager: SDLManager) {
self.sdlManager = sdlManager
audioData = Data()
audioRecordingState = .notListening
super.init()
-
- NotificationCenter.default.addObserver(self, selector: #selector(audioPassThruEnded(response:)), name: SDLDidReceivePerformAudioPassThruResponse, object: nil)
}
func stopManager() {
@@ -41,9 +35,9 @@ class AudioManager: NSObject {
guard audioRecordingState == .notListening else { return }
let recordingDurationMilliseconds: UInt32 = 5000
- let audioPassThruRequest = SDLPerformAudioPassThru(initialPrompt: "Starting sound recording", audioPassThruDisplayText1: "Say Something", audioPassThruDisplayText2: "Recording for \(recordingDurationMilliseconds / 1000) seconds", samplingRate: .rate16KHZ, bitsPerSample: .sample16Bit, audioType: .PCM, maxDuration: recordingDurationMilliseconds, muteAudio: true, audioDataHandler: audioDataHandler)
+ let performAudioPassThru = SDLPerformAudioPassThru(initialPrompt: "Starting sound recording", audioPassThruDisplayText1: "Say Something", audioPassThruDisplayText2: "Recording for \(recordingDurationMilliseconds / 1000) seconds", samplingRate: .rate16KHZ, bitsPerSample: .sample16Bit, audioType: .PCM, maxDuration: recordingDurationMilliseconds, muteAudio: true, audioDataHandler: audioDataReceivedHandler)
- sdlManager.send(request: audioPassThruRequest)
+ sdlManager.send(request: performAudioPassThru, responseHandler: audioPassThruEndedHandler)
}
/// Manually stops an on-going audio recording.
@@ -59,9 +53,9 @@ class AudioManager: NSObject {
// MARK: - Audio Pass Thru Notifications
-extension AudioManager {
+private extension AudioManager {
/// SDL streams the audio data as it is collected.
- fileprivate var audioDataHandler: SDLAudioPassThruHandler? {
+ var audioDataReceivedHandler: SDLAudioPassThruHandler? {
return { [unowned self] data in
guard data != nil else { return }
if self.audioRecordingState == .notListening {
@@ -75,24 +69,26 @@ extension AudioManager {
/// Called when `PerformAudioPassThru` request times out or when a `EndAudioPassThru` request is sent
///
/// - Parameter response: A SDLRPCNotificationNotification notification
- @objc func audioPassThruEnded(response: SDLRPCResponseNotification) {
- guard audioRecordingState == .listening else { return }
- audioRecordingState = .notListening
-
- switch response.response.resultCode {
- case .success: // The `PerformAudioPassThru` timed out or the "Done" button was pressed in the pop-up.
- if audioData == nil {
- sdlManager.send(AlertManager.alertWithMessageAndCloseButton("No audio recorded"))
- } else {
- // `audioData` contains the complete audio recording for the pass thru. SDL does not provide speech recognition, however the iOS Speech API or another third party library can be used for speech reconition.
- let pcmBuffer = convertDataToPCMFormattedAudio(audioData!)
- sdlManager.send(AlertManager.alertWithMessageAndCloseButton("Audio recorded!", textField2: "\(pcmBuffer)"))
+ var audioPassThruEndedHandler: SDLResponseHandler? {
+ return { [unowned self] (request, response, error) in
+ guard let response = response else { return }
+ self.audioRecordingState = .notListening
+
+ switch response.resultCode {
+ case .success: // The `PerformAudioPassThru` timed out or the "Done" button was pressed in the pop-up.
+ if let audioData = self.audioData, audioData.count == 0 {
+ self.sdlManager.send(AlertManager.alertWithMessageAndCloseButton("No audio recorded"))
+ } else {
+ let pcmBuffer = self.convertDataToPCMFormattedAudio(self.audioData!)
+ self.sdlManager.send(AlertManager.alertWithMessageAndCloseButton("Audio recorded!", textField2: "\(pcmBuffer)"))
+ }
+ case .aborted: // The "Cancel" button was pressed in the pop-up. Ignore this audio pass thru.
+ self.audioData = Data()
+ self.sdlManager.send(AlertManager.alertWithMessageAndCloseButton("Recording canceled"))
+ default:
+ self.audioData = Data()
+ self.sdlManager.send(AlertManager.alertWithMessageAndCloseButton("Recording unsuccessful", textField2: "\(response.resultCode.rawValue.rawValue)"))
}
- case .aborted: // The "Cancel" button was pressed in the pop-up. Ignore this audio pass thru.
- audioData = Data()
- sdlManager.send(AlertManager.alertWithMessageAndCloseButton("Recording cancelled"))
- default:
- sdlManager.send(AlertManager.alertWithMessageAndCloseButton("Recording unsuccessful", textField2: "\(response.response.resultCode.rawValue.rawValue)"))
}
}
}
@@ -101,12 +97,11 @@ extension AudioManager {
// MARK: - Audio Data Conversion
private extension AudioManager {
- /// Converts the audio data to PCM formatted audio that can be passed to iOS SFSpeech Framework, if desired. When doing the converstion, the audio format and sample rate should match those set in the `SDLPerformAudioPassThru`.
+ /// Converts the audio data to PCM formatted audio that can be passed, if desired, to the iOS SFSpeech framework (SDL does not provide speech recognition, however the SFSpeech framework or another third party library can be used for speech recognition). The audio format and sample rate should match those set in the `SDLPerformAudioPassThru`.
///
/// - Parameter data: The audio data
- /// - Returns: A AVAudioPCMBuffer object
+ /// - Returns: An AVAudioPCMBuffer object
func convertDataToPCMFormattedAudio(_ data: Data) -> AVAudioPCMBuffer {
- //
let audioFormat = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: false)
let numFrames = UInt32(data.count) / (audioFormat.streamDescription.pointee.mBytesPerFrame)
let buffer = AVAudioPCMBuffer(pcmFormat: audioFormat, frameCapacity: numFrames)
diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.h b/SmartDeviceLink_Example/Classes/ProxyManager.h
index 333bb6dbf..3e8a0e91b 100644
--- a/SmartDeviceLink_Example/Classes/ProxyManager.h
+++ b/SmartDeviceLink_Example/Classes/ProxyManager.h
@@ -5,8 +5,6 @@
#import <Foundation/Foundation.h>
@class SDLManager;
-@class SDLStreamingMediaManager;
-
typedef NS_ENUM(NSUInteger, ProxyTransportType) {
ProxyTransportTypeUnknown,
diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m
index 8d8af2389..1e89ffc74 100644
--- a/SmartDeviceLink_Example/Classes/ProxyManager.m
+++ b/SmartDeviceLink_Example/Classes/ProxyManager.m
@@ -2,6 +2,7 @@
// ProxyManager.m
// SmartDeviceLink-iOS
+#import "AudioManager.h"
#import "AppConstants.h"
#import "SmartDeviceLink.h"
#import "ProxyManager.h"
@@ -21,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
// Describes the first time the HMI state goes non-none and full.
@property (assign, nonatomic) SDLHMIFirstState firstTimeState;
+
@property (assign, nonatomic, getter=isTextEnabled) BOOL textEnabled;
@property (assign, nonatomic, getter=isHexagonEnabled) BOOL toggleEnabled;
@property (assign, nonatomic, getter=areImagesEnabled) BOOL imagesEnabled;
@@ -44,10 +46,10 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init {
self = [super init];
- if (self == nil) {
+ if (!self) {
return nil;
}
-
+
_state = ProxyStateStopped;
_firstTimeState = SDLHMIFirstStateNone;
@@ -89,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN
[weakSelf sdlex_updateProxyState:ProxyStateStopped];
return;
}
-
+
[weakSelf sdlex_updateProxyState:ProxyStateConnected];
[weakSelf sdlex_setupPermissionsCallbacks];
[weakSelf sdlex_showInitialData];
@@ -100,6 +102,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.sdlManager stop];
}
+
#pragma mark - Helpers
- (void)sdlex_showInitialData {
@@ -196,6 +199,7 @@ NS_ASSUME_NONNULL_BEGIN
logConfig.modules = [logConfig.modules setByAddingObject:sdlExampleModule];
logConfig.targets = [logConfig.targets setByAddingObject:[SDLLogTargetFile logger]];
// logConfig.filters = [logConfig.filters setByAddingObject:[SDLLogFilter filterByAllowingModules:[NSSet setWithObject:@"Transport"]]];
+ logConfig.globalLogLevel = SDLLogLevelDebug;
return logConfig;
}
@@ -261,11 +265,9 @@ NS_ASSUME_NONNULL_BEGIN
}
+ (SDLAddCommand *)sdlex_dialNumberCommandWithManager:(SDLManager *)manager {
- NSString *menuName = @"Dial Number";
- SDLMenuParams *commandMenuParams = [[SDLMenuParams alloc] initWithMenuName:menuName];
-
+ SDLMenuParams *commandMenuParams = [[SDLMenuParams alloc] initWithMenuName:ACDialPhoneNumberMenuName];
SDLAddCommand *dialNumberCommand = [[SDLAddCommand alloc] init];
- dialNumberCommand.vrCommands = [NSMutableArray arrayWithObject:menuName];
+ dialNumberCommand.vrCommands = [NSMutableArray arrayWithObject:ACDialPhoneNumberMenuName];
dialNumberCommand.menuParams = commandMenuParams;
dialNumberCommand.cmdID = @3;
dialNumberCommand.handler = ^(SDLOnCommand * _Nonnull command) {
@@ -294,6 +296,20 @@ NS_ASSUME_NONNULL_BEGIN
return dialNumberCommand;
}
++ (SDLAddCommand *)sdlex_recordAudioCommandWithManager:(SDLManager *)manager {
+ SDLMenuParams *commandMenuParams = [[SDLMenuParams alloc] initWithMenuName:ACRecordInCarMicrophoneAudioMenuName];
+ SDLAddCommand *recordAddCommand = [[SDLAddCommand alloc] init];
+ recordAddCommand.vrCommands = [NSMutableArray arrayWithObject:ACRecordInCarMicrophoneAudioMenuName];
+ recordAddCommand.menuParams = commandMenuParams;
+ recordAddCommand.cmdID = @4;
+ AudioManager *audioManager = [[AudioManager alloc] initWithManager:manager];
+ recordAddCommand.handler = ^(SDLOnCommand * _Nonnull command) {
+ [audioManager startRecording];
+ };
+
+ return recordAddCommand;
+}
+
+ (SDLSpeak *)sdlex_appNameSpeak {
SDLSpeak *speak = [[SDLSpeak alloc] init];
speak.ttsChunks = [SDLTTSChunk textChunksFromString:ExampleAppNameTTS];
@@ -427,7 +443,7 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)sdlex_prepareRemoteSystem {
- [self.sdlManager sendRequests:@[[self.class sdlex_speakNameCommandWithManager:self.sdlManager], [self.class sdlex_interactionSetCommandWithManager:self.sdlManager], [self.class sdlex_vehicleDataCommandWithManager:self.sdlManager], [self.class sdlex_dialNumberCommandWithManager:self.sdlManager], [self.class sdlex_createOnlyChoiceInteractionSet]]
+ [self.sdlManager sendRequests:@[[self.class sdlex_speakNameCommandWithManager:self.sdlManager], [self.class sdlex_interactionSetCommandWithManager:self.sdlManager], [self.class sdlex_vehicleDataCommandWithManager:self.sdlManager], [self.class sdlex_dialNumberCommandWithManager:self.sdlManager], [self.class sdlex_createOnlyChoiceInteractionSet], [self.class sdlex_recordAudioCommandWithManager:self.sdlManager]]
progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
SDLLogD(@"Commands sent updated, percent complete %f%%", percentComplete * 100);
} completionHandler:nil];
diff --git a/SmartDeviceLink_Example/Enum+SDLAudioRecordingState.swift b/SmartDeviceLink_Example/Enum+SDLAudioRecordingState.swift
new file mode 100644
index 000000000..e386c2cad
--- /dev/null
+++ b/SmartDeviceLink_Example/Enum+SDLAudioRecordingState.swift
@@ -0,0 +1,14 @@
+//
+// Enum+SDLAudioRecordingState.swift
+// SmartDeviceLink
+//
+// Created by Nicole on 4/23/18.
+// Copyright © 2018 smartdevicelink. All rights reserved.
+//
+
+import Foundation
+
+enum SDLAudioRecordingState {
+ case listening
+ case notListening
+}