- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Swift 创建一个应用程序。
我正确集成了语音转文本和文本转语音:我的应用程序运行完美。你可以找到我的项目here .
语音转文本后,应用程序向服务器发出 http 请求(发送识别的文本),并以声音方式再现响应(它是一个字符串,即:“好的,我将向您展示一些内容”)从文本到语音。但是,有一个大问题,我无法解决。
当应用程序以声音方式再现文本时,声音太慢,就好像它在后台一样,好像有什么比声音更重要的东西要再现(实际上什么也没有)。
调试后,我发现问题是在函数 recordAndRecognizeSpeech()
中使用audioEngine (AVAudioEngine) 开始的。在不使用此功能的情况下运行应用程序并播放随机文本,它就像一个魅力。
所以,在我看来,当应用程序以声音方式再现文本时,它认为仍然存在事件的音频引擎,因此音量非常慢。
但是,在复制文本之前,我调用了这些函数(查看 ac 函数内部,第 96 行):
audioEngine.stop()
audioEngine.reset()
如何解决这个问题?
编辑:
我找到了部分解决方案。现在,在应用程序有声播放文本之前,我的代码是:
audioEngine.inputNode.removeTap(onBus: 0)
audioEngine.stop()
audioEngine.reset()
recognitionTask?.cancel()
isRecording = false
microphoneButton.setTitle("Avvia..", for: UIControl.State.normal);
do {
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(AVAudioSession.Category.ambient)
try audioSession.setActive(false, options: .notifyOthersOnDeactivation)
} catch {
print(error)
}
make_request(msg: self.speech_result.text!)
.setCategory 函数有效,并且音量与默认值类似。当我尝试调用 recordAndRecognizeSpeech()
函数时,应用程序给出了以下异常:
VAEInternal.h:70:_AVAE_Check: 必需条件为 false: [AVAudioIONodeImpl.mm:910:SetOutputFormat: (IsFormatSampleRateAndChannelCountValid(hwFormat))]
这个异常是由.setCategory(AVAudioSession.Category.ambient)
引起的,它应该是.playAndRecord,但是使用这个值音量又变低了。
最佳答案
试试这个。
let speaker = AVSpeechSynthesizer()
func say(text: String, language: String) {
// Start audio session
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSession.Category.playAndRecord)
try audioSession.setMode(AVAudioSession.Mode.default)
try audioSession.setActive(true)
try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
} catch {
return
}
if speaker.isSpeaking {
speaker.stopSpeaking(at: .immediate)
} else {
myUtterance = AVSpeechUtterance(string: text)
myUtterance.rate = AVSpeechUtteranceDefaultSpeechRate
myUtterance.voice = AVSpeechSynthesisVoice(language: language)
myUtterance.pitchMultiplier = 1
myUtterance.volume = 2
DispatchQueue.main.async {
self.speaker.speak(myUtterance)
}
}
}
关于ios - AVSpeechSynthesizer 音量太低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53619027/
我找到了 --可以添加一个小的停顿,比如数字倒计时: 10--9--8--7--6--5--4--3--2--1-- 但我不知道如何添加一个长时间的停顿,比如 1 秒? 任何的想法? 最佳答案 在 S
我想在 AVSpeechSynthesizer 说话时在我的应用程序上显示一个 View ,并在它停止说话时让该 View 消失。 -(void)speakText { AVSpeechSyn
我正在我的应用程序中使用此 UI 实现 AVSpeechSynthesizer: 如何从 AVSpeechSynthesizer 话语中获取进度?我看到没有委托(delegate)方法或 API 来获
我有一个使用UICollectionView的快速应用程序。 UICollectionView 中的每个单元格都有一个显示一些文本的 View Controller 。我添加了两个按钮来启动和暂停 A
我正在尝试使用 Swift 创建一个应用程序。 我正确集成了语音转文本和文本转语音:我的应用程序运行完美。你可以找到我的项目here . 语音转文本后,应用程序向服务器发出 http 请求(发送识别的
是否可以在应用扩展中使用 AVSpeechSynthesizer? 我已经在我的应用程序中添加了应用程序操作扩展,并且在显示的默认 Controller 上,我在 - (void)viewDidApp
我正在使用 AVSpeechSynthesizer 读取一个字符串,但如果该字符串包含任何特殊字符(如表情符号微笑),它会报错。 如何清除字符串中的特殊字符但保留对日语、中文的支持? 最佳答案 将 N
我想知道语音合成器何时说完它的话语。可以这样做吗? 最佳答案 您是否考虑过设置 delegate为你的合成器? 关于ios - AVSpeechSynthesizer 检测到说话结束?,我们在Stac
我正在使用**AVSpeechSynthesizer**,以下是将文本传递给**AVSpeechSynthesizer**的代码。 func speakOutText(_ textToRead:Str
目前我有一张带有注释的 map ,当用户点击注释时会播放音频。我想添加一个播放/暂停按钮,但它不起作用,我不确定为什么。 AVSpeechSynthesizer - (void)mapView:(MK
我正在使用 AVSpeechSynthesizer 将 2 种语言的文字转为语音。有没有办法在单词的不同部分指定语音重音? 我试过将 ' 放在想要的元音前后,还尝试使用带有重音符号的元音,例如ó、ý
我正在使用下面的代码在我的应用程序中读出一个字符串。 var mySynthesizer = AVSpeechSynthesizer() var myUtterance = AVSpeechUtter
我一直在尝试使用 AVSpeechSynthesizer 从 UIWebView 读取文本。我想要的方法是: 使用JS获取屏幕顶部可见元素(即p、h1、h2、h3等) 使用 JS 将元素拆分为单词数组
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-au"]; 这行代码正是您如何更改 obj-c 中的语言的方法。但我想
我正在使用 AVSpeechSynthesizer 在我的 iOS 应用中进行文本到语音转换。 语音合成器在除运行 iOS 9.0.2 的 iPad 2(型号 A1395)以外的所有设备上都运行良好。
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我正在使用 AVSpeechSynthesizer 为一些文本数据发声,它第一次可以工作,但之后就没用了。 我收到以下消息。 错误:- AppName[859:101035] [AXTTSCommon
AVSpeechSynthesizer 似乎支持多代表英语(英国,美国...) 是否支持其他语言?法语、葡萄牙语……某处有这些语言的列表吗? 最佳答案 是的,确实如此。使用 AVSpeechSynth
我有一个应用程序,使用覆盖文本到语音的 swift avspeechsynthizer 运行良好。 avspeechsynehtizer 是否执行与文本相反的语音。 最佳答案 是的!您有可以使用的 S
我在我的 iOS 应用程序中使用 AVSpeechSynthesizer for TTS。但是没有调用 didFinishSpeechUtterance 方法。 这是我在 .h 中的代码: #impo
我是一名优秀的程序员,十分优秀!