首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发言前快速清除AVSpeechSynthesizer

发言前快速清除AVSpeechSynthesizer
EN

Stack Overflow用户
提问于 2017-03-30 04:08:27
回答 1查看 539关注 0票数 0

我正在使用下面的代码在我的应用程序中说出一个字符串。

代码语言:javascript
复制
var mySynthesizer = AVSpeechSynthesizer()
var myUtterance = AVSpeechUtterance(string: "Hello World!")
myUtterance.voice = AVSpeechSynthesisVoice(language: "en-US")
myUtterance.pitchMultiplier = 1.15
myUtterance.rate = 0.5
mySynthesizer.speak(utterance)

如果字符串随后被更改并被要求再次读取,它将在新字符串的末尾重复上一个字符串。

是否可以在开始之前清除AVSpeechSynthesizer?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-03-30 04:30:27

我让它在操场上发挥作用。不会重复任何内容。

代码语言:javascript
复制
//: Playground - noun: a place where people can play

import UIKit
import AVFoundation
import PlaygroundSupport

// this is needed otherwise the playground program exits before the speech is synthesized.
PlaygroundPage.current.needsIndefiniteExecution = true


var mySynthesizer = AVSpeechSynthesizer()
var helloUtterance = AVSpeechUtterance(string: "Hello World!")
helloUtterance.voice = AVSpeechSynthesisVoice(language: "en-US")
helloUtterance.pitchMultiplier = 1.25
helloUtterance.rate = 0.5
mySynthesizer.speak(helloUtterance)

let responseUtterance = AVSpeechUtterance(string: "Hey human. It's me, the world")
responseUtterance.pitchMultiplier = 0.75
responseUtterance.rate = 0.45
mySynthesizer.speak(responseUtterance)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43103179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档