实时获取麦克风语音信号

现在需要在PC(Linux环境)或ARM平台对语音信号进行实时录入,方法有两种:

  • linux下的设备驱动编程
  • 基于OpenFramework调用API

audio driver

目前Linux下常用的声卡驱动程序主要有两种:OSS和ALSA。现在主流的是ALSA(Advanced Linux Sound Architecture)。笔者实测Ubuntu12.10,/dev下的音频驱动是/dev/snd目录下的设备文件。包括以下文件:

by-path controlC0 controlC0D0 controlC1D0 pwmC0D0c pwmC0D0p pwmC1D3p seq timer。

按照文档对设备文件进行读写即可以录入语音了。


openFrameworks

官网上说openFrameworks is an open source C++ toolkit for creative coding.

它是一个集成了OpenGL,OpenCV ,rtAudio,OpenAL等视频音频库的框架。

看一个creative coding的例子,可以互动的梵高 星空。里面触碰互动采用Kinect和OpenCV实现[2][3]。


audioInputExample

这个程序用来语音录入。

   int main( ){

   ofSetupOpenGL(1024,768, OF_WINDOW);          
   // <-------- setup the GL context
   // this kicks off the running of my app
   ofRunApp( new ofApp());
   }

这是整个程序的入口函数。

ofSetupOpenGL(int w, int h, int screenMode)是ofSetupOpenGL的一个重载函数,这个实现用来设置屏幕的大小。

ofRunApp( new ofApp())是运行自己编写的App程序,ofApp是一个包含很多函数具体实现的类。它重载的是ofRunApp(ofPtr OFSA),其中ofPtr OFSA是一个模板类。

 template <typename T>
 class ofPtr: public std::shared_ptr<T>
 {
 public:

  ofPtr()
  : std::shared_ptr<T>() { }

  template<typename Tp1>
    explicit
    ofPtr(Tp1* __p)
  : std::shared_ptr<T>(__p) { }
  ......
}

References

[1].http://www.ibm.com/developerworks/cn/linux/l-audio/

[2].http://www.36kr.com/p/82473.html

[3].http://baike.baidu.com/view/3766855.htm?fr=aladdin

[4].http://cddxhy.blog.163.com/blog/static/3399928320120179363102/



Previous     Next
/
Published under (CC) BY-NC-SA in categories linux  tagged with