- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发 Bot 应用程序,在这里我有 2 个功能
// Starts an AVAudio Session
NSError *error;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];
// Starts a recognition process, in the block it logs the input or stops the audio
// process if there's an error.
recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
AVAudioInputNode *inputNode = audioEngine.inputNode;
recognitionRequest.shouldReportPartialResults = YES;
recognitionTask = [speechRecognizer recognitionTaskWithRequest:recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
BOOL isFinal = NO;
if (result) {
// Whatever you say in the microphone after pressing the button should be being logged
// in the console.
NSLog(@"RESULT:%@",result.bestTranscription.formattedString);
self.inputToolbar.contentView.textView.text = result.bestTranscription.formattedString;
self.inputToolbar.contentView.rightBarButtonItem.enabled = YES;
isFinal = !result.isFinal;
}
if (error) {
if (audioEngine != NULL) {
[audioEngine stop];
[inputNode removeTapOnBus:0];
recognitionRequest = nil;
recognitionTask = nil;
}
}
}];
// Sets the recording format
AVAudioFormat *recordingFormat = [inputNode outputFormatForBus:0]; //[[AVAudioFormat alloc] initStandardFormatWithSampleRate:44100 channels:1];
[inputNode installTapOnBus:0 bufferSize:1024 format:recordingFormat block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
[recognitionRequest appendAudioPCMBuffer:buffer];
}];
// Starts the audio engine, i.e. it starts listening.
[audioEngine prepare];
[audioEngine startAndReturnError:&error];
NSLog(@"Say Something, I'm listening");
最佳答案
尝试使用这个:
AVAudioRecorder *recorder;
NSTimer *levelTimer;
double lowPassResults;
-(void)configureRecorder{
// AVAudioSession already set in your code, so no need for these 2 lines.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
lowPassResults = 0;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.05 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
} else
NSLog(@"%@", [error description]);
}
}
- (void)levelTimerCallback:(NSTimer *)timer {
[recorder updateMeters];
const double ALPHA = 0.05;
double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
NSLog(@"lowPassResults: %f",lowPassResults);
// Use here a threshold value to stablish if there is silence or speech
if (lowPassResults < 0.1) {
NSLog(@"Silence");
} else if(lowPassResults > 0.5){
NSLog(@"Speech");
}
}
关于ios - 如果用户停止说话,如何自动停止语音识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46337097/
我在 uipickerview 中有一个 uitextfield,我试图禁用任何类型的格式,我使用 UIResponderStandardEditActions 来禁用随之而来的所有操作,但我不知道如
如何让 Python 说出一些文字? 我可以将 Festival 与子进程一起使用,但我无法控制它(或者可能在交互模式下,但它不会是干净的)。 是否有 Python TTS 库?像 Festival、
在我的应用程序中,我想知道是否有任何可以阅读印地文文本的 tts 引擎。我的代码 tts.setLanguage(Locale.US); 很遗憾,Android 不支持印地语。请参阅下面支持的语言环境
@ 目录 创建页面布局 创建手势控件 创建TalkBox 创建动画 拖拽物动画
我有一个简单的 Angular 模态,是用 Angular ui.bootstrap 引发的。它打开得很好,传递值等,但不会关闭或取消。我认为这是 $scopes 的讨论问题。我知道每个模式都有自己的
scss基本上是sass功能的改进实现。我的工作区使用.scss文件。什么是正确的或通用的方式来指代scss时说?我们刚刚把这些文件称为“sass”文件。在只使用scss而不使用sass文件的环境中,
有谁知道我在哪里可以找到一个好的起点来编写一个函数,该函数接受一个字符串并将其转换为 leet speak? function stringToLeetSpeak($string) { // Lo
我目前正在实现视频通话应用程序,例如使用 Twilio Video 的 Google Hangout。我想在后台显示当时正在讲话的人的视频。 是否可以检测谁在使用 Twilio Video JS SD
所以我找到了这段代码: #!/usr/bin/python import sys #for cmd line argv import time #for delay import p
我想让我的机器人能够制作一个 webhook,由命令触发,然后 webhook 可以在一定间隔内说出消息。我想获取已创建的 webhook 的 token 和 id,然后将其放在一个持续不断的 set
我想让 Alexa 说出对意图的响应,但是通过手动调用包含 Alexa 技能代码的 Lambda 函数,而不是直接对 Echo 说出意图。 例如,您能否以某种方式(通过 AWS-SDK 或通过物联网“
我编写 Python 有一段时间了,但 DJango 和一般的 Web 编程对我来说是新的。 我在 Python View 中执行了一个很长的操作。由于我认为 local() 函数需要很长时间才能返回
我是一名优秀的程序员,十分优秀!