I'm simply trying to record a 30 second sound byte and save it to a predesignated file. I can't seem to find any info on how to go about doing this. Does anybody have any suggestions? They'd be much appreciated!
13 9988
Hi,
I have a voicerecorder class that will record a .WAV file in windows mobile using the built in technologies (i.e. no 3rd party software needed at all)
I am at home now, I have the code in the office so I can't get at it until Monday, I'll try and see if I have a backup here... but I am not sure.
Mark
Thanks a whole lot, Mark! I'm not in that much of a hurry anyways.
I gotta say, you are always on the ball, and prompt. Thanks a lot for that!
Thanks a whole lot, Mark! I'm not in that much of a hurry anyways.
I gotta say, you are always on the ball, and prompt. Thanks a lot for that!
No worries mate, glad to help!
This is a class called VoiceRecorder.c s ... It's fairly simple to use. It's a slightly modified version of one I found on thecodeproject a while back (I'm VERY sorry, I can't find the original URL) it launches the inbuilt audio recording facilities of Windows Mobile.
You invoke it by using -
VoiceRecorder vr = new VoiceRecorder("myFileName.wav");
-
vr.show();
-
And it behaves just like a dialogbox.
It took me AGES to try and get something like this working, so it's always nice when we can skip out all that hassle and help eachother. -
using System;
-
using System.Data;
-
using System.Runtime.InteropServices;
-
-
#region Attempt 1
-
namespace MyNameSpace
-
{
-
public class VoiceRecorder
-
{
-
#region API prototypes
-
[DllImport("voicectl.dll", EntryPoint = "VoiceRecorder_Create")]
-
private unsafe static extern IntPtr VoiceRecorder_Create(CM_VOICE_RECORDER* voicerec);
-
-
[DllImport("coredll.dll", EntryPoint = "GetForegroundWindow")]
-
private unsafe static extern IntPtr GetForegroundWindow();
-
#endregion
-
-
[StructLayout(LayoutKind.Sequential)]
-
public unsafe struct CM_VOICE_RECORDER
-
{
-
public int cb;
-
public wndStyle dwStyle;
-
public int xPos;
-
public int yPos;
-
public IntPtr hwndParent;
-
public int id;
-
public char* lpszRecordFileName;
-
}
-
-
public enum wndStyle : uint
-
{
-
VRS_NO_OKCANCEL = 0x0001, // No OK/CANCLE displayed
-
VRS_NO_NOTIFY = 0x0002, // No parent Notifcation
-
VRS_MODAL = 0x0004, // Control is Modal
-
VRS_NO_OK = 0x0008, // No OK displayed
-
VRS_NO_RECORD = 0x0010, // No RECORD button displayed
-
VRS_PLAY_MODE = 0x0020, // Immediately play supplied file when launched
-
VRS_NO_MOVE = 0x0040, // Grip is removed and cannot be moved around by the user
-
VRS_RECORD_MODE = 0x0080, // Immediately record when launched
-
VRS_STOP_DISMISS = 0x0100 // Dismiss control when stopped
-
}
-
-
private unsafe CM_VOICE_RECORDER _VoiceRec;
-
private IntPtr _hRecorder;
-
private string wavFile = @"\My Documents\VRec_0.wav";
-
-
private IntPtr _Hwnd = (IntPtr)0;
-
-
public IntPtr Hwnd
-
{
-
get { return _Hwnd; }
-
set
-
{
-
_VoiceRec.hwndParent = value;
-
_Hwnd = value;
-
}
-
}
-
-
public unsafe VoiceRecorder(string _audioFile)
-
{
-
wavFile = _audioFile;
-
_hRecorder = new IntPtr();
-
char[] temp = new char[200];
-
-
this.Hwnd = GetForegroundWindow();
-
-
// Populate temp with the file path of the WAV file
-
Buffer.BlockCopy(wavFile.ToCharArray(), 0, temp, 0, 2 * wavFile.Length);
-
-
fixed (char* lpszFileName = temp)
-
{
-
_VoiceRec = new CM_VOICE_RECORDER();
-
-
_VoiceRec.hwndParent = _Hwnd;
-
_VoiceRec.dwStyle = wndStyle.VRS_NO_MOVE | wndStyle.VRS_MODAL;
-
_VoiceRec.cb = (int)Marshal.SizeOf(_VoiceRec);
-
_VoiceRec.xPos = -1;
-
_VoiceRec.yPos = -1;
-
_VoiceRec.lpszRecordFileName = lpszFileName;
-
}
-
}
-
-
// Show the voice recorder
-
public unsafe void Show()
-
{
-
fixed (CM_VOICE_RECORDER* _VoiceRecPtr = &_VoiceRec)
-
{
-
_hRecorder = VoiceRecorder_Create(_VoiceRecPtr);
-
}
-
}
-
}
-
}
-
#endregion
-
Wonderful! Goodness the only thing i had to do to get that code working in it's entirety was to turn on the unsafe code switch. Works like an absolute charm. I never would have figured that out myself. Thanks so much mark!
Wonderful! Goodness the only thing i had to do to get that code working in it's entirety was to turn on the unsafe code switch. Works like an absolute charm. I never would have figured that out myself. Thanks so much mark!
No problem pal, had the same thing myself a while back trying to find it, glad to help!
Hi Everyone,
Sorry I'm asking a question about such an old post, but I'm getting the following errors
The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DllImportAttri bute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DllImportAttri bute' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'StructLayout' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'StructLayoutAt tribute' could not be found (are you missing a using directive or an assembly reference?)
Any suggestions?
Thanks!
James
do you definitely have
using System.Runtime. InteropServices ;
In your code? Is this running on a mobile device?
Cheers,
Mark
Fantastic! That sorts it! Thanks Mark!
Is it possible to embed the recording controls in the form? I'm programming for windows mobile 6, so am currently using the wm6 emulator that comes with visual studio 2008
Thanks
James
Dear markmcgookin,
This code help me a lot and i want to know is it possible to record sound in mp3 format.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MLH |
last post by:
Edit, Insert Object & choose Wave Object, the following
OLE object thing gets inserted onto the form...
Microsoft Sound Recorder
Version 5.1 (Build 2600.xpsp2.030422-1633: Service Pack 1)
Copyright 1981-2001 Microsoft Corporation
PCM 22.050 kHz, 8 Bit, Mono
If I double-click the icon-looking thing on the form after setting its
.Enabled property to true AND its .Verb property to -2, the Microsoft
|
by: Andrew Banks |
last post by:
I own VS.NET and am wondering what else I need to develop for the Smartphone
2002 platform?
What languages can I develop for the Smartphone 2002 in and does it support
..NET?
Thanks in advance,
Andrew Banks
|
by: Ray Ackley |
last post by:
I'm experiencing a threading problem that's really perplexing me. I
have a multithreaded application that reads car ECU information that's
sent over the serial port by the ECU and received by the
laptop/program.
I'll try to give a concise synopsis as the program is easily 10k+
lines.
main.cs - contains the application start function. Here's the entire
code (minus misc junk) as it's rather small -
|
by: wina |
last post by:
Hai, anyone know how to Load a Wav file and put the loaded file as an input for FFT function?
I'm building application for SmartPhone using Vb.Net2003 and OpenNETCF library v1.4. It's a violin tuner, which capture sound, load the sound and pass it to FFT, then process the FFT output to frequency.
For sound loading, i use File.OpenRead which has result in Stream datatype. For FFT, i'm going to use OpenNETCF.FFT which need input of array...
|
by: Abubakar |
last post by:
Hi,
I want my app's user to be able to record sound through my app and save it
to the/some file. How can I do that? Are there any classes in the .net
framework that let us do this? Or will I have to buy some thirdparty
components, in which case plz suggest some cool n tested links.
Regards,
...ab
| |
by: Darhl Thomason |
last post by:
I'm developing an app for a Smartphone and want to add a text box that only
accepts numbers (much like in the contacts, the phone # fields only accept
numbers).
Thanks!
Darhl
|
by: Ian |
last post by:
I am trying to save the current record on a form before opening a
report, doesn’t sound to hard does it? The code on a buttons on click
event goes like this:
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
'First save record
I used this for many years with problems using Access 97, when the
database is upgraded to Access 2000 or later I occasionally get an error
message saying “Save Command is not available now”.
|
by: andrewdb |
last post by:
I have been working with a database that was already created by somebody else, who now no longer works here, so I cant ask any questions.
None the less, there is a table 'Ascertainment' which prior to my changes new record was saved in the Table, but when you bring up the form it was blank, the input for new record consisted of Text Boxes.
I wanted to validate the data, and changed the text boxes to combo boxes, now new record does not...
|
by: LTCCTL |
last post by:
Hi all,
I am creating an application which will send/receive messages, whenever a message comes in it should play a sound file(wave/mid or any other format).
How can we do it?
I am using C#.NET, Windows Mobile Smartphone SDK, Compact framework 2.0
Thanks in advance
LTCCTL
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |