项目作者: mhy12345

项目描述 :
实时音频分析库,支持声学特征提取和实时节拍检测
高级语言: Python
项目地址: git://github.com/mhy12345/rcaudio.git
创建时间: 2018-05-12T09:05:14Z
项目社区:https://github.com/mhy12345/rcaudio

开源协议:MIT License

下载


rcaudio : A Realtime Audio Recording & Analyzing Library

Introduction

rcaudio is a real-time audio analysis library that allows you to simply record audio through a microphone and analyze.

It supports real-time analysis of :

  • The raw audio data
  • Volume
  • Beat Information
  • DIY method extraction function

For chinese documentation : 中文文档

Installation

  1. pip install rcaudio

Usage

CoreRecorder

CoreRecorder is used to fetch raw data. When started, the audio data will be stored in the CoreRecorder.buffer.

  1. from rcaudio import CoreRecorder
  2. CR = CoreRecorder(
  3. time = 10, #How much time to record
  4. sr = 1000 #sample rate
  5. )
  6. CR.start()
  7. while True:
  8. if not CR.buffer.empty():
  9. x = CR.buffer.get()
  10. print('*'*int(abs(x)))

SimpleRecorder

In most cases, we use SimpleRecorder. For efficiency consideration, the SimpleRecorder should only be instantiated once.

This class can register several Analyzer.

When the function start() called, It will begin to record through microphone, and refresh the status of all the Analyzer

Analyzers

All class extended from BaseAnalyzer can be registered into SimpleRecorder. For example VolumeAnalyzer can get the current volume of the microphone.

  1. import time
  2. from rcaudio import SimpleRecorder,VolumeAnalyzer
  3. SR = SimpleRecorder()
  4. VA = VolumeAnalyzer(rec_time = 1)
  5. SR.register(VA)
  6. SR.start()
  7. while True:
  8. print("VOLUME : ",VA.get_volume())
  9. time.sleep(1)

And beat analyzer can predict the beats from the music. (However, there will be some delay.)

  1. SR = SimpleRecorder(sr = 20000)
  2. BA = BeatAnalyzer(rec_time = 15, initial_bpm = 120, smooth_ratio = .8)
  3. SR.register(BA)
  4. SR.start()
  5. while True:
  6. print(BA.block_until_next_beat())

A FeatureAnalyzer can use to generate all user defined acoustic features. Just override the data_process function. (Current function are the calculation of the Zero Crossing Rate.

  1. SR = SimpleRecorder(sr = 1000)
  2. FA = FeatureAnalyzer(refresh_time = 1)
  3. SR.register(FA)
  4. SR.start()
  5. cpos = 0
  6. while True:
  7. if len(FA.result) > cpos:
  8. print(FA.result[cpos])
  9. cpos += 1
  10. time.sleep(.01)

Some notes

Most function has the time delay about 1-2 seconds. I did lot effort to let the BeatAnalyzer looked as it is real-time. However, for the FeatureAnalyzer, if the feature extraction function are too slow compare to the microphone recording, the dalay may become huge. Decrease the sample rates would be a solution, but better solution would be DIY a analyzer yourself.