×
Namespaces

Variants
Actions
(Difference between revisions)

Using QMicrophone

From Nokia Developer Wiki
Jump to: navigation, search
galazzo (Talk | contribs)
(Galazzo -)
hamishwillee (Talk | contribs)
m (Hamishwillee -)
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Qt Mobility]][[Category:Qt Quick]][[Category:MeeGo]][[Category:Multimedia]][[Category:Symbian]][[Category:Code Examples]]
+
[[Category:Qt Mobility]][[Category:Qt Quick]][[Category:MeeGo Harmattan]][[Category:Symbian]][[Category:Code Examples]][[Category:Audio]]
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
 
|sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] -->
Line 24: Line 24:
  
 
== Introduction ==
 
== Introduction ==
This article explains how to QMicrophone, a class to easy manage microphone on your device. Will be explained how to record a file and manage volume. The idea behind the volume management is the ability to trigger events with sounds. Take, for example, to change a page, snapping his fingers, or trigger an event when environment noise exceeds a threshold.
+
This article explains how to use QMicrophone, a class to easily manage microphone on your device. It will also explain how to record a file and manage volume. The idea behind the volume management is the ability to trigger events with sounds. Take, for example, to change a page, snapping his fingers, or trigger an event when environment noise exceeds a threshold.
  
== Using QMicrophone ==
+
== Before starting ==
 
+
# Download source code from [http://projects.developer.nokia.com/QMicrophone/browser here]
+
 
# Include '''QMicrophone''' directory into your project
 
# Include '''QMicrophone''' directory into your project
  
 
=== .pro ===
 
=== .pro ===
<code cpp>
+
<code cpp-qt>
 
         include(./QMicrophone/microphone.pri)
 
         include(./QMicrophone/microphone.pri)
 
</code>
 
</code>
  
 
=== main.cpp ===
 
=== main.cpp ===
<code cpp>
+
<code cpp-qt>
 
#include <QtGui/QApplication>
 
#include <QtGui/QApplication>
 
#include "qmlapplicationviewer.h"
 
#include "qmlapplicationviewer.h"
Line 61: Line 59:
 
== QML ==
 
== QML ==
 
=== How to Record Audio Files ===
 
=== How to Record Audio Files ===
<code cpp>
+
<code cpp-qt>
 
import QtQuick 1.1
 
import QtQuick 1.1
 
import Microphone 1.0
 
import Microphone 1.0
Line 139: Line 137:
  
 
=== How to manage Volume ===
 
=== How to manage Volume ===
<code cpp>
+
<code cpp-qt>
 
import QtQuick 1.1
 
import QtQuick 1.1
 
import Microphone 1.0
 
import Microphone 1.0
Line 161: Line 159:
  
 
=== Restrictions ===
 
=== Restrictions ===
If you are already using Microphone to record an audio file, you cannot use in the same time volume management, due the fact the resource it's already busy.
+
At moment, if you are already using Microphone to record an audio file, you cannot use in the same time volume management, due the fact the resource it's already busy.
  
 
=== Work in progress ===
 
=== Work in progress ===
 +
* recording and volume management in the same time
 
* clap or fingers snapping detection
 
* clap or fingers snapping detection
 
* simple command voice detection, like "up", "down", "left", "right", "stop"...
 
* simple command voice detection, like "up", "down", "left", "right", "stop"...
 +
 +
==Source Code ==
 +
You may download the source code from [http://projects.developer.nokia.com/QMicrophone/browser here]
 +
 +
== Related Links ==
 +
* [http://www.developer.nokia.com/Community/Wiki/How_to_access_and_manage_the_Microphone_raw_data_in_WP7 How to access and manage the Microphone raw data in WP7]

Revision as of 08:32, 14 June 2013

Article Metadata
Tested with
Devices(s): Nokia N8, Nokia C7-00, N950
Compatibility
Platform(s): Symbian^3 and later, Qt 4.7 and later, Meego
Symbian
Platform Security
Capabilities: UserEnvironment
Article
Keywords: Microphone, lmmfdevsound,multimedia
Created: galazzo (04 Apr 2012)
Last edited: hamishwillee (14 Jun 2013)

Contents

Introduction

This article explains how to use QMicrophone, a class to easily manage microphone on your device. It will also explain how to record a file and manage volume. The idea behind the volume management is the ability to trigger events with sounds. Take, for example, to change a page, snapping his fingers, or trigger an event when environment noise exceeds a threshold.

Before starting

  1. Include QMicrophone directory into your project

.pro

        include(./QMicrophone/microphone.pri)

main.cpp

#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
 
#include <QtDeclarative>
#include "QMicrophone/qmicrophone.h"
 
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
 
qmlRegisterType<QMicrophone>("Microphone", 1, 0, "Microphone");
 
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
viewer.setMainQmlFile(QLatin1String("qml/QMicrophoneSample/main.qml"));
viewer.showExpanded();
 
return app->exec();
}

QML

How to Record Audio Files

import QtQuick 1.1
import Microphone 1.0
 
Rectangle {
Column {
height: parent.height
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
Rectangle {
width: parent.width
height: 100
radius: 1
 
Text {
text: qsTr("Start recording for 5 sec")
horizontalAlignment: Text.AlignLeft
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
microphone.startRecording("test.wav", 5000);
}
}
}
 
Rectangle {
width: parent.width
height: 100
radius: 1
 
Text {
text: qsTr("Start recording")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
microphone.startRecording("test.wav");
}
}
}
 
Rectangle {
width: parent.width
height: 100
radius: 1
 
Text {
text: qsTr("Stop recording")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
microphone.stopRecording();
}
}
}
 
}
 
Microphone {
id:microphone
onRecordingStarted: console.log("Start recording")
onRecordingStopped: console.log("Stop recording")
}
}

startRecording has two parameters:

  • filename where audio will be saved
  • recording time in msec. If not set recording will continue until stopRecording will be called

Note.pngNote: Note that audio is saved in raw PCM format.

How to manage Volume

import QtQuick 1.1
import Microphone 1.0
 
Rectangle {
Microphone {
id:microphone
threshold: 150
onThresholdExceeded: {
console.log(volume)
}
}
 
Component.onCompleted: {
microphone.startVolumeAnalysis();
}
}

This functionality is very useful if you wish to trigger an event when Volume exceed the threshold.

Restrictions

At moment, if you are already using Microphone to record an audio file, you cannot use in the same time volume management, due the fact the resource it's already busy.

Work in progress

  • recording and volume management in the same time
  • clap or fingers snapping detection
  • simple command voice detection, like "up", "down", "left", "right", "stop"...

Source Code

You may download the source code from here

Related Links

58 page views in the last 30 days.