0

我在我的 iOS 应用程序中使用了 amazon polly Joanna,但我无法听到我输入的文本的第一个单词。谁能帮我解决这个问题。贝娄是我正在使用的代码

let input = AWSPollySynthesizeSpeechURLBuilderRequest()

// Text to synthesize
input.text = "Sample text"

// We expect the output in MP3 format
input.outputFormat = AWSPollyOutputFormat.mp3

// Choose the voice ID
input.voiceId = AWSPollyVoiceId.joanna

// Create an task to synthesize speech using the given synthesis input
let builder = AWSPollySynthesizeSpeechURLBuilder.default().getPreSignedURL(input)

// Request the URL for synthesis result
builder.continueOnSuccessWith(block: { (awsTask: AWSTask<NSURL>) -> Any? in
    // The result of getPresignedURL task is NSURL.
    // Again, we ignore the errors in the example.
    let url = awsTask.result!

    // Try playing the data using the system AVAudioPlayer
    self.audioPlayer.replaceCurrentItem(with: AVPlayerItem(url: url as URL))
    self.audioPlayer.play()

    return nil
})
4

1 回答 1

0

您是否正在通过蓝牙设备收听?通常这些设备会进入空闲模式并有启动时间。您无法控制用户的蓝牙设备,您可以将一段无声的短 MP3 加载到 AVPlayer 中,并在需要语音之前立即播放。或者,您可以设置通知中心任务以在设备运行时循环播放:

    NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: myPlayer.currentItem, queue: nil) { (_) in
    myPlayer.seek(to: kCMTimeZero)
    myPlayer.play()
}

这是您可以使用的无声 mp3: https ://www.dropbox.com/s/0h6cdqx9yvbw2xs/silence.mp3?dl=0

于 2018-08-09T17:19:35.497 回答