algolia / voice-overlay-ios

🗣 An overlay that gets your user’s voice permission and input as text in a customizable UI
https://alg.li/voice
MIT License
544 stars 62 forks source link

After setting up the project, while specking I am getting error(VoiceOverlay-Demo[640:138261] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)) #19

Closed imSandeepSingh closed 5 years ago

imSandeepSingh commented 5 years ago

Hello,

I setup the demo project & giving all permission as you had mentioned in Redme section. But while testing application is not able to Listen anything & every time I am getting one error which was mentioned below :

VoiceOverlay-Demo[640:138261] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Speaker (type: Speaker)

My ViewController file :

// // ViewController.swift // VoiceOverlay-Demo // // Created by Guy Daher on 25/06/2018. // Copyright © 2018 Algolia. All rights reserved. //

import UIKit import InstantSearchVoiceOverlay import Speech

class ViewController: UIViewController, VoiceOverlayDelegate {

let voiceOverlayController = VoiceOverlayController() let button = UIButton() let label = UILabel()

override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib.

let margins = view.layoutMarginsGuide

button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
label.text = "Result Text from the Voice Input"

label.font = UIFont.boldSystemFont(ofSize: 16)
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.textAlignment = .center

button.setTitle("Start using voice", for: .normal)
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)
button.backgroundColor = UIColor(red: 255/255.0, green: 64/255.0, blue: 129/255.0, alpha: 1)
button.layer.cornerRadius = 7
button.layer.borderWidth = 1
button.layer.borderColor = UIColor(red: 237/255, green: 82/255, blue: 129/255, alpha: 1).cgColor

label.translatesAutoresizingMaskIntoConstraints = false
button.translatesAutoresizingMaskIntoConstraints = false

self.view.addSubview(label)
self.view.addSubview(button)

NSLayoutConstraint.activate([
  label.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 10),
  label.trailingAnchor.constraint(equalTo: margins.trailingAnchor, constant: -10),
  label.topAnchor.constraint(equalTo: margins.topAnchor, constant: 110),
  ])

NSLayoutConstraint.activate([
button.leadingAnchor.constraint(equalTo: margins.leadingAnchor, constant: 10),
button.trailingAnchor.constraint(equalTo: margins.trailingAnchor, constant: -10),
button.centerYAnchor.constraint(equalTo: margins.centerYAnchor, constant: 10),
button.heightAnchor.constraint(equalToConstant: 50),
])

voiceOverlayController.delegate = self

// If you want to start recording as soon as modal view pops up, change to true
voiceOverlayController.settings.autoStart = true
voiceOverlayController.settings.autoStop = true
voiceOverlayController.settings.showResultScreen = true

voiceOverlayController.settings.layout.inputScreen.subtitleBulletList = ["Suggestion1", "Suggestion2"]

}

@objc func buttonTapped() { // First way to listen to recording through callbacks voiceOverlayController.start(on: self, textHandler: { (text, final, extraInfo) in print("callback: getting (String(describing: text))") print("callback: is it final? (String(describing: final))")

  if final {
    let string = "Hello, World!"
    let utterance = AVSpeechUtterance(string: string)
    utterance.voice = AVSpeechSynthesisVoice(language: "en-US")

    let synth = AVSpeechSynthesizer()
    synth.speak(utterance)
    // here can process the result to post in a result screen
    Timer.scheduledTimer(withTimeInterval: 1.5, repeats: false, block: { (_) in
      let myString = text
      let myAttribute = [ NSAttributedString.Key.foregroundColor: UIColor.red ]
      let myAttrString = NSAttributedString(string: myString, attributes: myAttribute)

      self.voiceOverlayController.settings.resultScreenText = myAttrString
      self.voiceOverlayController.settings.layout.resultScreen.titleProcessed = "BLA BLA"

    })
  }
}, errorHandler: { (error) in
  print("callback: error \(String(describing: error))")
}, resultScreenHandler: { (text) in
  print("Result Screen: \(text)")
}
)

} // Second way to listen to recording through delegate func recording(text: String?, final: Bool?, error: Error?) { if let error = error { print("delegate: error (error)") } if error == nil { label.text = text } } }

Regards, Sandeep

spinach commented 5 years ago

Hey,

You can check this StackOverflow thread which explains this error. It doesn't seem related to the this library if I understand correctly, so I'm closing this for now