- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用文字转语音,开始音频效果很好,但我无法停止。这是我如何开始音频:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
[[self view] setNeedsDisplay];
[self synthesizeInBackground];
[queue waitUntilAllOperationsAreFinished];
[self setIsSpeaking: false];
[[self view] setNeedsDisplay];
});
背景合成
- (void) synthesizeInBackground {
XLog(@"-----------------------------------entered");
queue = [[NSOperationQueue alloc] init];
XLog(@"queue: %@", queue);
operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(synthesize) object:nil];
XLog(@"operation: %@", operation);
[queue addOperation: operation];
}
合成
- (void)synthesize {
XLog(@"-----------------------------------entered");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
callback_userdata userdata;
NSError *error = nil;
self.paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
self.documentsDirectory = [self.paths objectAtIndex:0];
self.path = [self.documentsDirectory stringByAppendingPathComponent:@"readSearchresults.txt"];
IvonaStreamer *streamer = [[IvonaStreamer alloc] initWithVoice:voice withText:[NSString stringWithContentsOfFile:self.path encoding:NSUTF8StringEncoding error:&error] atSpeed:[NSNumber numberWithFloat:-1]];
//IvonaStreamer *streamer = [[IvonaStreamer alloc] initWithVoice:voice withText:@"Dies ist ein Testtext." atSpeed:[NSNumber numberWithFloat:-1]];
if (streamer == nil) {
XLog(@"Cannot start streamer");
[self setTtsError: @"Cannot start streamer"];
return;
}
userdata.speak = &(self->isSpeaking);
userdata.streamer = streamer;
#define NUM_BUFFERS 3
#define BUFFER_SIZE 22050
OSStatus err;
AudioQueueRef audioQueue;
//XLog(@"audioQueue: %d", audioQueue);
XLog(@"[voice getSampleRate]: %i", [voice getSampleRate]);
AudioStreamBasicDescription deviceFormat;
deviceFormat.mSampleRate = [voice getSampleRate];
deviceFormat.mFormatID = kAudioFormatLinearPCM;
deviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
deviceFormat.mBytesPerPacket = 2;
deviceFormat.mFramesPerPacket = 1;
deviceFormat.mBytesPerFrame = 2;
deviceFormat.mChannelsPerFrame = 1;
deviceFormat.mBitsPerChannel = 16;
deviceFormat.mReserved = 0;
XLog(@"deviceFormat.mSampleRate: %f", deviceFormat.mSampleRate);
/*
XLog(@"deviceFormat.mSampleRate: %f", deviceFormat.mSampleRate);
XLog(@"deviceFormat.mFormatID: %lu", deviceFormat.mFormatID);
XLog(@"deviceFormat.mFormatFlags: %lu", deviceFormat.mFormatFlags);
XLog(@"deviceFormat.mBytesPerPacket %lu", deviceFormat.mBytesPerPacket);
XLog(@"deviceFormat.mFramesPerPacket %lu", deviceFormat.mFramesPerPacket);
XLog(@"deviceFormat.mBytesPerFrame %lu", deviceFormat.mBytesPerFrame);
XLog(@"deviceFormat.mChannelsPerFrame %lu", deviceFormat.mChannelsPerFrame);
XLog(@"deviceFormat.mBitsPerChannel %lu", deviceFormat.mBitsPerChannel);
XLog(@"deviceFormat.mReserved %lu", deviceFormat.mReserved);
*/
err = AudioQueueNewOutput(&deviceFormat,
AudioQueueCallback,
&userdata,
CFRunLoopGetCurrent(),
kCFRunLoopCommonModes,
0,
&audioQueue);
if (err != noErr) {
XLog(@"Cannot create audio output");
[self setTtsError: @"Cannot create audio output"];
[streamer stop];
return;
}
AudioQueueAddPropertyListener(audioQueue, kAudioQueueProperty_IsRunning,
AudioQueuePropertyListener, NULL);
for (int i = 0; i < NUM_BUFFERS; i++) {
AudioQueueBufferRef buffer;
err = AudioQueueAllocateBuffer(audioQueue, BUFFER_SIZE, &buffer);
if (err != noErr) {
XLog(@"Cannot allocate audio buffer");
[self setTtsError: @"Cannot allocate audio buffer"];
[streamer stop];
return;
}
AudioQueueCallback(&userdata, audioQueue, buffer);
}
err = AudioQueueStart(audioQueue, NULL);
if (err != noErr) {
XLog(@"Cannot start audio");
[self setTtsError: @"Cannot start audio"];
[streamer stop];
return;
}
CFRunLoopRun();
[streamer stop];
[pool release];
}
音频队列回调
void AudioQueueCallback(void *userData, AudioQueueRef audioQueue,
AudioQueueBufferRef buffer)
{
//XLog(@"-----------------------------------entered");
void *data = buffer->mAudioData;
UInt32 num_bytes = buffer->mAudioDataBytesCapacity;
//XLog(@"num_bytes: %lu", num_bytes);
UInt32 to_write = num_bytes / sizeof(short);
//XLog(@"to_write: %lu", to_write);
NSInteger num_samples;
//XLog(@"num_samples: %i", num_samples);
IvonaStreamer *streamer = ((callback_userdata*) userData)->streamer;
bool *enabled = ((callback_userdata*) userData)->speak;
//XLog(@"streamer.getWarnings: %@", streamer.getWarnings);
if(!*enabled) {
XLog(@"!*enabled");
AudioQueueStop(audioQueue, false);
}
num_samples = [streamer synthSamples:to_write toCArray:data];
//XLog(@"num_samples: %i", num_samples);
if (num_samples > 0) {
//XLog(@"num_samples > 0");
buffer->mAudioDataByteSize = num_samples * sizeof(short);
AudioQueueEnqueueBuffer(audioQueue, buffer, 0, NULL);
} else {
//XLog(@"! (num_samples > 0)");
AudioQueueStop(audioQueue, false);
}
}
音频队列属性监听器
void AudioQueuePropertyListener(void *userData, AudioQueueRef audioQueue,
AudioQueuePropertyID id)
{
XLog(@"-----------------------------------entered");
UInt32 isRunning, size = sizeof(isRunning);
AudioQueueGetProperty(audioQueue, kAudioQueueProperty_IsRunning, &isRunning, &size);
if (isRunning == 0) {
XLog(@"isRunning == 0");
CFRunLoopStop(CFRunLoopGetCurrent());
}
if (isRunning != 0) {
XLog(@"nicht null#######");
}
}
我尝试在其他方法(UIAlertView 委托(delegate)方法)中停止:
if (alertView.tag == 997) {
if (buttonIndex == 0) {
XLog(@"vorlesen abbrechen geklickt.");
[queue cancelAllOperations];
AudioQueueRef audioQueue;
//AudioQueueDispose(audioQueue, false);
AudioQueueStop(audioQueue, false);
}
我正在取消所有操作并调用 AudioQueueDispose,也尝试使用 AudioQueueStop,但这里没有任何效果。
所以我的问题是,如何在这里停止音频?
最佳答案
AudioQueueStop 应该可以工作并且足够了。从苹果文档中,AudioQueueReset 是从 AudioQueueStop 调用的。AudioQueueDispose 以后想再启动的话有点过分了。
关于ios - 如何停止 AudioQueue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11033829/
我对 AudioQueues 有一个基本的疑问,我正在使用 AudioQueue 进行录音,并且基本上遵循 SpeakHere 应用程序。我发现每当我在 AudioQueue 对象上使用 api: A
我创建了一个 iOS 5/iOS 6 应用程序,该应用程序的显示屏可响应用户演奏的音高变化。它使用示例 SpeakHere 代码中的记录功能,但实际上并不保存文件,因为它旨在实时响应。 我现在想扩展这
我需要读取音频样本值。我正在使用该 audioQueue 回调(来自 Apple SpeakHere 示例): UInt32 samplesCount = inCompleteAQBuffe
我正在使用 AudioQueues 获取音频样本的 block 。 这是我的回调方法 void AQRecorder::MyInputBufferHandler( void *
我正在使用文字转语音,开始音频效果很好,但我无法停止。这是我如何开始音频: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORI
我的应用使用ffmpeg 解析彩信流 到缓冲区,并使用音频队列 播放缓冲数据。现在我可以确认缓冲数据是好的,但我无法播放。播放结构基于AudioFileStreamExample demo客户端,可以
我目前正在构建一个应用程序,该应用程序从我的 iPhone 的麦克风中读取音频,然后进行一些处理和视觉处理。当然,我首先从音频开始,但有一个小问题。 我将采样率定义为 44100 Hz,并将缓冲区定义
我目前正在开发音频 DSP 应用程序。该项目需要直接访问和修改音频数据。现在我可以使用 AudioQueue 成功访问和修改原始音频数据,但在播放过程中遇到错误。任何修改后的输出音频都是噪音。 简而言
我有一个基于 AudioQueue 的应用程序几乎可以完美运行。但是,我遇到了一个问题。当我调用 AudioQueueAllocateBuffer 时,我特别请求缓冲区大小为 512(因为我正在对数据
我正在尝试设置一个音频队列来播放流式音频数据。到目前为止,这就是我所拥有的: var audioStream = AudioStreamBasicDescription() audio
尽管应用程序按预期工作,但我在控制台中收到一条消息,我想更详细地了解它。 设置如下。创建一个 AVAudioPlayer 并加载一个 .m4a 文件(长度为 03:22,大小为 618 KB)。该文件
我有一个音频队列,可以正确播放、停止和暂停,但我发现 AudioQueueStop() 函数需要很长时间才能执行。 我想立即停止然后重新开始播放音频队列,并且想知道这样做的最快方法是什么。 在我的项目
我正在尝试使用声能从麦克风确定每分钟节拍数 (BPM),我想我已经找到了确定 BPM 的部分,但在获取原始数据时遇到了一些麻烦。 该示例基于 Apples SpeakHere 应用程序 - 基于我正在
好像无法播放提示音 AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); 当 AudioQueue 用于录制音频时。那是对的吗?也许我做错了什么。除
我分析了iPhone开发论坛的“SpeakHere”示例代码。 启动 AudioQueue 的代码如下.. AudioTimeStamp ats = {0}; AudioQueueStart(mQue
我正在使用AudioQueue读取AudioBuffer,它间接读取来自Mic的音频输入,但看来,回调没有命中, 下面是简要的逻辑 1--运行音频线程 2 -- 创建音频队列 3 -- 配置音频队列,
我正在编写一个类,该类打开 AudioQueue 并分析其特征,然后在某些条件下可以开始或结束从已实例化的 AudioQueue 中写出文件。这是我的代码(完全基于 SpeakHere),它打开 Au
如何获取audioQueue中音乐的总持续时间。我正在使用 NSTimeInterval AQPlayer::getCurrentTime() { NSTimeInterval timeInt
我的音频流有问题(这是内部有 6 个 channel 的 LPCM 流)。但是当我通过 AudioQueue 在 iPhone 上播放这个流时,我只听到前两个 channel 。 这里AudioQue
我正在构建一个应用程序,该应用程序需要真正准确的位置音频,直至建模耳间时间差 (ITD) 水平,即立体声 channel 之间的轻微延迟差异随声音相对于听众的位置而变化。不幸的是,iPhone 的 O
我是一名优秀的程序员,十分优秀!