我正在尝试语音识别样本.如果我开始通过麦克风识别我的演讲,那么我试图让iPhone听到那个公认的文字.这是工作.但是,声音太低了.你可以指导我吗?
而不是,如果我尝试简单的按钮操作,使用AVSpeechUtterance代码,音量是正常的.
之后,如果我选择startRecognise()方法,音量太低.
我的守则
func startRecognise()
{
let audioSession = AVAudioSession.sharedInstance() //2
do
{
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
try audioSession.setMode(AVAudioSessionModeDefault)
try audioSession.setMode(AVAudioSessionModeMeasurement)
try audioSession.setActive(true, with: .notifyOthersOnDeactivation)
try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.speaker)
}
catch
{
print("audioSession properties weren't set because of an error.")
}
recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
guard let inputNode = audioEngine.inputNode else {
fatalError("Audio engine has no input node")
}
guard let recognitionRequest = recognitionRequest else {
fatalError("Unable to create an SFSpeechAudioBufferRecognitionRequest object")
}
recognitionRequest.shouldReportPartialResults = true
recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest, …Run Code Online (Sandbox Code Playgroud) avaudioplayer ios avspeechsynthesizer swift sfspeechrecognizer
我努力把苹果语音合成音频单元的东西(只适用于MacOS的,不是的iOS)到AudioKit,我已经建立了一个AKSpeechSynthesizer类(最初由wangchou在此创建pull请求)和演示项目都可以在发展AudioKit的分支.
我的项目与这个可可语音合成示例非常相似,但在这个项目中,速率变量可以在每分钟的低字数(40)到高数字(300 ish)之间平滑变化和变化.但是,我的项目以默认速率175开始,任何更改都会使速率降低到爬行速度 - 除非您将其更改为350,否则速度会超快.
我不知道我在做什么与这个例子有什么不同,因为两个项目都依赖
SetSpeechProperty(speechChannel, kSpeechRateProperty, newRate as NSNumber?)
Run Code Online (Sandbox Code Playgroud)
设定费率.
最大的区别是我的合成器被设置为音频单元,而我认为工作示例只使用默认输出到扬声器.
频率(音调)或调制(pitchMod)的其他参数也表现出奇怪的行为,但它们不那么引人注意,而且这两个项目的工作都有点滑稽.
有人可以告诉我为什么我的工作不起作用或通过拉取请求修复它?任何帮助将在代码中受到高度赞赏和归属.
谢谢!
我发现--可以添加一个小停顿,如数字倒计时:
10--9--8--7--6--5--4--3--2--1--
Run Code Online (Sandbox Code Playgroud)
但我不知道如何添加一个长暂停,如1秒?
任何的想法?
我想做的是让我的应用程序AVSpeechSynthesizer在背景音频应用播放音频时使用话语.当我的应用发言时,我希望后台应用的音频"昏暗",然后在我的应用完成讲话后返回原始音量.
在我的AudioFeedback课堂上,我初始化我设置AVAudioSessions如下:
self.session = [AVAudioSession sharedInstance];
NSError *error;
[self.session setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionDuckOthers error:&error];
Run Code Online (Sandbox Code Playgroud)
每当我想说一个新的话语时,我都会做以下事情.我按照AVSpeechSynthesizer的问题提出的建议,任何解决方法?每次创建一个新的AVSpeechSynthesizer以"确保"始终接收取消(它似乎工作,我不知道为什么).
- (AVSpeechUtterance *) utteranceWithString: (NSString *) string
{
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:string];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-ES"];
[utterance setRate:(AVSpeechUtteranceDefaultSpeechRate+AVSpeechUtteranceMinimumSpeechRate)/2.0];
return utterance;
}
- (void) sayString: (NSString *) string cancelPrevious: (BOOL) cancelPrevious
{
[self.session setActive:enabled error:nil];
if (cancelPrevious) {
AVSpeechSynthesizer *oldSynthesizer = self.voice;
self.voice = nil;
[oldSynthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
self.voice = [[AVSpeechSynthesizer alloc] init];
self.voice.delegate = self;
}
// …Run Code Online (Sandbox Code Playgroud) 以下代码:
AVSpeechSynthesizer * speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString: @"112"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];
speechSynthesizer speakUtterance:utterance];
Run Code Online (Sandbox Code Playgroud)
导致与设备说:"百和十二条"(英式拼写)
但是,如果你改为编号112:
NSString * wordNumber = nil;
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-GB"]];
[numberFormatter setNumberStyle:NSNumberFormatterSpellOutStyle];
wordNumber = [numberFormatter stringFromNumber:@(112)];
Run Code Online (Sandbox Code Playgroud)
现在wordNumber包含"一百一十二"(没有和粒子).
所以:
@"112" -> AVSpeechSynthesizer -> "one hundred and twelve"
@"112" -> NSNumberFormatter -> "one hundred twelve"
Run Code Online (Sandbox Code Playgroud)
我怎样才能用数字和数字来音译数字,即英文拼写?
我只是不知道怎么做......
我在这里和谷歌搜索,人们谈论AVSpeechSynthesizerDelegate,但我无法使用它.
我想在演讲结束时准确地运行一个函数.
我怎样才能做到这一点?如果我必须使用代表,我该怎么办?
我试过这样的方式:
func speechSynthesizer(synthesizer: AVSpeechSynthesizer, didFinishSpeechUtterance utterance: AVSpeechUtterance) {
falando = false
print("FINISHED")
}
Run Code Online (Sandbox Code Playgroud)
这是我在开发人员的文档中找到的功能之一,尽管演讲被告知并且没有打印任何内容.
我试图把A类:AVSpeechSynthesizerDelegate放进去,然后我会做Speech.delegate = self(Speech是A的一个属性,AVSpeechSynthesizer类型),但它说A不符合协议NSObjectProtocol.
演讲结束后如何运行某些功能(甚至是打印件)?
谢谢!
我喜欢通过呼叫接收器扬声器播放音频,目前我正在使用它来播放一些文本作为音频。
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:_strTextCheck];
AVSpeechSynthesizer *syn = [[AVSpeechSynthesizer alloc] init];
[syn speakUtterance:utterance];
Run Code Online (Sandbox Code Playgroud)
我知道了,但这不适合AVSpeechSynthesizer:
[AVAudioSession overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
Run Code Online (Sandbox Code Playgroud)
正确地,它可以在普通扬声器上工作,但是我想通过呼叫接收器扬声器播放,是否可以做到这一点?
我的控制台因这些错误而被垃圾邮件:
[MobileAssetError:1]无法复制资产属性
无法获取属性'LocalURL':错误域= MobileAssetError代码= 1"无法复制资产属性"UserInfo = {NSDescription =无法复制资产属性}
复制匹配资产回复:XPC_TYPE_DICTIONARY {count = 2,transaction:0,voucher = 0x0,contents ="Assets"=>:{length = 1237 bytes,contents = 0x62706c6973743030d4010203040506636458247665727369 ...}"Result"=>:0}
复制资产属性回复:XPC_TYPE_DICTIONARY {count = 1,transaction:0,voucher = 0x0,contents ="Result"=>:1}
当它开始垃圾邮件控制台时非常烦人.我已经读过像禁用OS_ACTIVITY_MODE这样的东西可以抑制这些日志,但我想找到它的来源并按原样处理它......
发生这种情况是因为我使用了AVSpeechSynthesizer,如下所示:
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
self.synthesizer setDelegate:self];
self.speedCameraAhead = [AVSpeechUtterance speechUtteranceWithString:NSLocalizedString(@"Caution: Blah blah blah!",nil)];
[self.speedCameraAhead setRate:0.5f];
Run Code Online (Sandbox Code Playgroud) 我制作了一个可以在后台朗读单词 (TTS) 的应用程序。
但是在我收到此中断通知后,播放器将停止。
AVSpeechSynthesizer Audio interruption notification: {
AVAudioSessionInterruptionTypeKey = 1;
AVAudioSessionInterruptionWasSuspendedKey = 1;
}
Run Code Online (Sandbox Code Playgroud)
在我得到如下所示的解决方案后,添加通知并实现以下代码。
然而,我发现AVAudioSessionInterruptionTypeEnded永远不会出现。即使我将启动功能放入AVAudioSessionInterruptionTypeBegan仍然不起作用。
我的问题是,如何在收到中断通知后保持我的 AVSpeechSynthesizer 工作?
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionInterruption:) name:AVAudioSessionInterruptionNotification object:aSession];
- (void)handleAudioSessionInterruption:(NSNotification*)notification {
NSNumber *interruptionType = [[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey];
NSNumber *interruptionOption = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey];
switch (interruptionType.unsignedIntegerValue) {
case AVAudioSessionInterruptionTypeBegan:{
[self interruptHandler];
[self playObject];
} break;
case AVAudioSessionInterruptionTypeEnded:{
if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume) {
// Here you should continue playback.
[self playObject];
}
} break;
default:
break;
}
}
- …Run Code Online (Sandbox Code Playgroud) 我希望能够测试哪些文本转语音可供我的 iOS 应用程序与 AVSpeechSynthesis 一起使用。生成已安装声音的列表很容易,但 Apple 将其中一些设置为禁止应用程序使用,我想知道哪些。
例如,考虑以下测试代码 (swift 5.1):
import AVFoundation
...
func voiceTest() {
let speechSynthesizer = AVSpeechSynthesizer()
let voices = AVSpeechSynthesisVoice.speechVoices()
for voice in voices where voice.language == "en-US" {
print("\(voice.language) - \(voice.name) - \(voice.quality.rawValue) [\(voice.identifier)]")
let phrase = "The voice you're now listening to is the one called \(voice.name)."
let utterance = AVSpeechUtterance(string: phrase)
utterance.voice = voice
speechSynthesizer.speak(utterance)
}
}
Run Code Online (Sandbox Code Playgroud)
当我打电话时voiceTest(),控制台输出是这样的:
en-US - Nicky (Enhanced) - 2 [com.apple.ttsbundle.siri_female_en-US_premium]
en-US - Aaron - 1 [com.apple.ttsbundle.siri_male_en-US_compact] …Run Code Online (Sandbox Code Playgroud)