首页 \ 问答 \ AudioRecorder读取是否有等待状态?(Does AudioRecorder read ever has a wait state?)

AudioRecorder读取是否有等待状态?(Does AudioRecorder read ever has a wait state?)

伙计们,

我正在通过设备的麦克风读取音频。 这是在后台线程中运行的伪代码:

while(true) {
   if (stopRecordingRequested()) {
       break;
   }
   int bytesRead = recorder.read(in, inSize);
   // do the processing
}

我注意到即使房间里有静音,方法“读取”也会返回数据。

我正在考虑一个紧凑的循环,例如上面的那个可能只是固定CPU,即使房间是沉默的。

是否可以配置录音机,使read()等到有噪音?

或者,也许有一种不同于CPU的不同技术。

预先感谢您的帮助。


Folks,

I am reading audio off the devices's microphone. Here is the pseudo code that is being run in a background thread:

while(true) {
   if (stopRecordingRequested()) {
       break;
   }
   int bytesRead = recorder.read(in, inSize);
   // do the processing
}

What I noticed is that method "read" returns data even if there is silence in the room.

I am thinking a tight loop such as the one above may simply peg the CPU even when the room is silent.

Is it possible to configure the audio recorder such that read() just waits until there is some noise?

Or, perhaps there is a different technique that doesn't peg the CPU.

Thank you in advance for your help.


原文:https://stackoverflow.com/questions/19437917
更新时间:2023-02-13 17:02

最满意答案

我不确定其他实现是如何做到这一点的,但至少Weld使用Filter本身来处理对话,因此你的过滤器需要在过滤器链中的那个之后。


I'm not sure how other implementations do this, but at least Weld uses a Filter itself to handle conversations, so your filter would need to be after that one in the filter chain.

相关问答

更多
  • 此方法仅适用于会话范围的JSF @ManagedBean ,而不适用于CDI @Named bean。 您需要@ @Inject它作为过滤器的属性。 @Inject private User user; This approach works for session scoped JSF @ManagedBean only, not for CDI @Named bean. You need to @Inject it as a property of the filter. @Inject privat ...
  • 您不能使用new创建CDI bean,也不能将构造函数用于任何类型的初始化逻辑。 这背后的原因是CDI bean(如EJB,Spring bean,JSF bean)具有独立的生命周期,并由相关容器管理。 你不能依赖于“传统”的理解来调用new的时间(和频率)。 使用producer来创建新bean,并使用@PostConstruct来创建后执行的任何逻辑。 这应该为您提供CDI的良好开端。 随意发表更多问题:) You must not create a CDI bean using new, nor u ...
  • 我不确定其他实现是如何做到这一点的,但至少Weld使用Filter本身来处理对话,因此你的过滤器需要在过滤器链中的那个之后。 I'm not sure how other implementations do this, but at least Weld uses a Filter itself to handle conversations, so your filter would need to be after that one in the filter chain.
  • 我不明白这个问题的重点。 如果你有一个业务层和使用EJB的可能性,我会寻求一个持有业务逻辑和JPA交互的@Stateless ,并将一个特定的业务接口公开给客户端。 无论如何,如果你只是在做一个select而没有别的,也许是为了在前端填充你的数据表,我建议像这样注释你的业务方法: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public List findByWhateverCriteria(String p ...
  • 事实上,你似乎混合了CDI Beans和JSF Beans,说实话,你翻译的例子看起来很奇怪,我只是把它扔出窗外。 因为,JSF也有它自己的依赖注入,除非你有一个非常具体的用例(比如说ServletFilter),否则你不会自己从作用域地图中提取东西。 澄清CDI使用http://en.wikipedia.org/wiki/Inversion_of_control原则并自己“提取”东西是一种反模式。 此外,CDI bean由CDI容器创建和管理(几乎在所有情况下都是Weld或OWB),你根本无法从exter ...
  • Rick Hightower编写了一个很好的扩展库,支持将Spring bean注入CDI bean,反之亦然: http://rick-hightower.blogspot.com/2011/04/cdi-and-spring-living-in-harmony.html Rick Hightower wrote a nice Extension library which supports to inject Spring beans into CDI beans and vice versa: htt ...
  • 我找到了解决方案。 我一步一步地做了什么: 我从DataServiceImpl bean中删除了LoginController ,并将带有@LoggedIn注释的UserAccount注入到DataController bean中: @Named @ViewScoped public class DataController implements Serializable { //other fields and methods @Inject @LoggedIn pri ...
  • 哇,你甚至可以添加所有的SpingFramework来做:)这应该做的工作: @javax.ejb.Singleton @javax.ejb.Startup public class Startup { @PostConstruct public void start() { System.out.println("start"); } } 的pom.xml javax
  • 我使用它的唯一方法是在MyFaces CODI中使用@ViewAccessScoped。 CDI允许扩展,因此您所要做的就是将CODI jar文件包含在您的应用程序中。 即使您使用的是Mojarra而不是MyFaces,这也有效。 所以,如果你想使用CDI注释,这是我的建议。 我尝试使用ConversationScoped注释一段时间但我无法让它方便地工作。 一旦我开始使用CODI,我的所有问题就消失了。 The only way that I got this to work is to use @Vie ...
  • 这可以通过自定义ConfigurableNavigationHandler来实现。 实现JSF NavigationHandler public class NavigationHandlerTest extends ConfigurableNavigationHandler { private NavigationHandlerTest concreteHandler; public NavigationHandlerTest(NavigationHandler concreteHandler) ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。