2017-06-14 240 views
1

我在Swift中創建了一個應用程序,它使用Twilio & CallKit撥打電話。在通話過程中,我想通過電話的耳機揚聲器播放音頻,例如「您已經接聽了2分鐘......」或至少有一個內置的系統音頻聲音。在通話期間播放音頻

它會的工作方式類似於如何導航,當他們宣佈的方向,當你在通話

我怎樣才能做到這一點的應用程序工作嗎?

我已經看過這裏的一些類似的問題,但我無法得到答案或更新的答案。

回答

1

找到一種方法來做到這一點是通過使用內置的AVSpeechSynthesizer。看看下面

public func sayMessage(message: String) { 
    do { 
     try setCategory(AVAudioSessionCategoryPlayAndRecord) 
     try setActive(true) 
     let synth = AVSpeechSynthesizer() 
     print("Routes:: \(currentRoute.outputs)") 
     if let currentChannels = currentRoute.outputs.first?.channels { 
      synth.outputChannels = currentChannels 
      print("Found channels \(currentChannels)") 
     } 
     let myUtterance = AVSpeechUtterance(string: message) 
     synth.speak(myUtterance) 

    } catch { 
     print(error) 
    } 
} 
+0

代碼,您也可以使用'AVAudioPlayer'播放錄製的聲音,喜歡這裏:https://stackoverflow.com/questions/24043904/creating-and-playing-a-sound-in -迅速 – philnash