Qt AudioInput流:“ UnknownError”

时间:2018-07-15 14:03:53

标签: c++ qt qaudioinput

我正在尝试使用QT API从麦克风读取音频数据,并且在设置QIODevice时遇到了一些麻烦,该设备可以让我将数据读取到缓冲区中。

下面是我现有的代码:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/user/login

Django Version: 2.0.5
Python Version: 3.6.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'user']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\core\handlers\exception.py" in inner
  35.             response = get_response(request)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\core\handlers\base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\core\handlers\base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\views\generic\base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\utils\decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\views\decorators\debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\utils\decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\utils\decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\utils\decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\utils\decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\utils\decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\contrib\auth\views.py" in dispatch
  66.         return super().dispatch(request, *args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\views\generic\base.py" in dispatch
  89.         return handler(request, *args, **kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\views\generic\edit.py" in get
  133.         return self.render_to_response(self.get_context_data())

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\contrib\auth\views.py" in get_context_data
  99.         context = super().get_context_data(**kwargs)

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\views\generic\edit.py" in get_context_data
  66.             kwargs['form'] = self.get_form()

File "C:\Users\bhask\Miniconda3\envs\batchbook\lib\site-packages\django\views\generic\edit.py" in get_form
  33.         return form_class(**self.get_form_kwargs())

Exception Type: TypeError at /user/login
Exception Value: __init__() got an unexpected keyword argument 'request'

我跑步时的输出是:

int main() {
    QAudioInput *audio;

    // Specifying format
    QAudioFormat format;
    format.setSampleRate(16000);
    format.setChannelCount(1);
    format.setSampleSize(8);
    format.setCodec("audio/pcm");
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::UnSignedInt);

    QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
    qWarning() << "Device being used:" << info.deviceName();

    if (!info.isFormatSupported(format)) {
        qWarning() << "Default format not supported, trying to use the nearest.";
        format = info.nearestFormat(format);
    }

    // Setting up the input
    audio = new QAudioInput(format);
    qWarning() << "\nAudio initialisation error:" << audio->error();
    qWarning() << "Audio initialisation state:" << audio->state() << "\n";


    QIODevice *inputStream = audio->start();
    qWarning() << "Audio stream start error:" << audio->error();
    qWarning() << "Audio stream start state:" << audio->state() << "\n";

    if (inputStream->waitForReadyRead(1000) == false) {
        qWarning() << inputStream->errorString();
        exit(1);
    }

    char input_data[512];
    while (true) {
        inputStream->read(input_data,512);
    }

    return 0;
}

我确定问题的部分原因在于QObject :: startTimer错误,该错误显然与QAudioInput对象内部发生的事情有关,但我无法跟踪这是从内部来的通过查阅文档了解QAudioInput对象。

总而言之,我想知道的是

  • 当我调用start()时,QAudioInput内部发生了什么,为什么会引起上面显示的警告?
  • 在哪里可以找到start()函数的实现,以便可以了解发生了什么?

0 个答案:

没有答案