Skip to content

Commit

Permalink
Merge pull request #976 from watson-developer-cloud/mdk/965-stt-with-…
Browse files Browse the repository at this point in the history
…airpods

fix(SpeechToTextV1): Add configureSession parameter to RecognizeMicrophone
  • Loading branch information
Mike Kistler authored Jun 28, 2019
2 parents 24b328f + 87f5aed commit f32c12b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Source/SpeechToTextV1/SpeechToText+Recognize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ extension SpeechToText {
By default, no customer ID is associated with the data.
- parameter compress: Should microphone audio be compressed to Opus format?
(Opus compression reduces latency and bandwidth.)
- parameter configureSession: A Boolean value that specifies whether to configure the AVAudioSession.
When `true`, the AVAudioSession is set to a standard configuration for microphone input. When `false`,
the current AVAudioSession configuration is used. To use an AVAudioSession configuration other than
the standard microphone configuration, set the configuration in your application and specify `false`
for the **configureSession** parameter. Default is `true`.
- parameter headers: A dictionary of request headers to be sent with this request.
- parameter completionHandler: A function executed when the request completes with a successful result or error
*/
Expand All @@ -152,13 +157,16 @@ extension SpeechToText {
learningOptOut: Bool? = nil,
customerID: String? = nil,
compress: Bool = true,
configureSession: Bool = true,
headers: [String: String]? = nil,
callback: RecognizeCallback)
{
// make sure the AVAudioSession shared instance is properly configured
do {
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: .default, options: [.defaultToSpeaker, .mixWithOthers])
if configureSession {
try audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: .default, options: [.defaultToSpeaker, .mixWithOthers])
}
try audioSession.setActive(true)
} catch {
let failureReason = "Failed to setup the AVAudioSession sharedInstance properly."
Expand Down

0 comments on commit f32c12b

Please sign in to comment.