自然语音 1.0.2

自然语音 1.0.2

Aimmatic 维护。



  • Aimmatic开发团队

自然语音移动SDK For iOS

此库允许您将自然语音功能集成到您的iOS应用程序中。

需要API密钥。您可以通过我们的解决方案台获得免费API密钥。

https://www.aimmatic.com/solution-desk.html

邮箱:[email protected]

请允许几小时的时间回复。

功能

示例

使用方法

要求

• iOS 8.0+

• xCode 9

Cocoapods

pod 'NaturalVoice'

安装

pod install

Info.plist

自然语音需要位置服务和麦克风权限,您需要将这些键添加到Info.plist

<key>NSMicrophoneUsageDescription</key>
<string>YOUR_DESCRIPTION</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>YOUR_DESCRIPTION</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>YOUR_DESCRIPTION</string>

在Info.plist中添加您的ApiKey

<key>AimMaticNaturalVoiceApiKeyDescription</key>
<string>YOUR_API_KEY</string>

使用语音服务

获取支持的语言

VoiceLanguageManager.shared.getSupportLanguages { languages in }

配置

VoiceRecordStrategy.language = language
VoiceRecordStrategy.maxRecordDuration = 30
VoiceRecordStrategy.maxRecordDurationPolicy = .sendImmediately
VoiceRecordStrategy.speechTimeout = 2
VoiceRecordStrategy.speechTimeoutPolicy = .sendImmediately

开始录音

VoiceRecorder.shared.startRecording(recordStarted: { meta in

}, recordEnded: { response in

}, recordSent: { response in

}, recordFailed: { error in

})

处理阻碍

开始录音时

let recordStared: VoiceRecordStarted = { (meta: VoiceFileMeta?) in

}

录音完成时

let recordEnded: VoiceRecordEnded = { (response: VoiceRecordEndResponse?) in
            
}

发送录音时

let recordSent: VoiceRecordSent = { (response: VoiceRecordSendResponse?) in
            
}

录音失败时

let recordFailed: VoiceRecordFailed = { (error: Error?) in
            
}

处理策略.userChoice,当录音完成时

if response?.policy == .userChoice {
    let controller = UIAlertController(title: "Send or Abort?", message: nil, preferredStyle: .alert)
    controller.addAction(UIAlertAction(title: "Send", style: .default, handler: { action in
        /* Send recorded file */
        response?.send()
    }))
    controller.addAction(UIAlertAction(title: "Abort", style: .cancel, handler: { action in
        /* Abort sending recorded file */
        response?.abort()
    }))
    self.present(controller, animated: true, completion: {})             
}

停止录制

这将覆盖之前设置的策略

VoiceRecordStrategy.maxRecordDurationPolicy

有决定地停止

VoiceRecorder.shared.stopRecording(policy: .userChoice)

立即停止并发送

VoiceRecorder.shared.stopRecording(policy: .sendImmediately)

停止并发取消发送

VoiceRecorder.shared.stopRecording(policy: .cancel)