473,800 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Record & save a sound byte from within smartphone app (C#)

31 New Member
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!
Nov 8 '08 #1
13 9988
markmcgookin
648 Recognized Expert Contributor
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
Nov 8 '08 #2
Cyprus106
31 New Member
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!
Nov 9 '08 #3
markmcgookin
648 Recognized Expert Contributor
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

Expand|Select|Wrap|Line Numbers
  1. VoiceRecorder vr = new VoiceRecorder("myFileName.wav");
  2. vr.show();
  3.  
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.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Runtime.InteropServices;
  4.  
  5. #region Attempt 1
  6. namespace MyNameSpace
  7. {
  8.     public class VoiceRecorder
  9.     {
  10.         #region API prototypes
  11.         [DllImport("voicectl.dll", EntryPoint = "VoiceRecorder_Create")]
  12.         private unsafe static extern IntPtr VoiceRecorder_Create(CM_VOICE_RECORDER* voicerec);
  13.  
  14.         [DllImport("coredll.dll", EntryPoint = "GetForegroundWindow")]
  15.         private unsafe static extern IntPtr GetForegroundWindow();
  16.         #endregion
  17.  
  18.         [StructLayout(LayoutKind.Sequential)]
  19.         public unsafe struct CM_VOICE_RECORDER
  20.         {
  21.             public int cb;
  22.             public wndStyle dwStyle;
  23.             public int xPos;
  24.             public int yPos;
  25.             public IntPtr hwndParent;
  26.             public int id;
  27.             public char* lpszRecordFileName;
  28.         }
  29.  
  30.         public enum wndStyle : uint
  31.         {
  32.             VRS_NO_OKCANCEL = 0x0001, // No OK/CANCLE displayed
  33.             VRS_NO_NOTIFY = 0x0002, // No parent Notifcation
  34.             VRS_MODAL = 0x0004, // Control is Modal    
  35.             VRS_NO_OK = 0x0008, // No OK displayed
  36.             VRS_NO_RECORD = 0x0010, // No RECORD button displayed
  37.             VRS_PLAY_MODE = 0x0020, // Immediately play supplied file when launched
  38.             VRS_NO_MOVE = 0x0040, // Grip is removed and cannot be moved around by the user
  39.             VRS_RECORD_MODE = 0x0080, // Immediately record when launched
  40.             VRS_STOP_DISMISS = 0x0100 // Dismiss control when stopped
  41.         }
  42.  
  43.         private unsafe CM_VOICE_RECORDER _VoiceRec;
  44.         private IntPtr _hRecorder;
  45.         private string wavFile = @"\My Documents\VRec_0.wav";
  46.  
  47.         private IntPtr _Hwnd = (IntPtr)0;
  48.  
  49.         public IntPtr Hwnd
  50.         {
  51.             get { return _Hwnd; }
  52.             set
  53.             {
  54.                 _VoiceRec.hwndParent = value;
  55.                 _Hwnd = value;
  56.             }
  57.         }
  58.  
  59.         public unsafe VoiceRecorder(string _audioFile)
  60.         {
  61.             wavFile = _audioFile;
  62.             _hRecorder = new IntPtr();
  63.             char[] temp = new char[200];
  64.  
  65.             this.Hwnd = GetForegroundWindow();
  66.  
  67.             // Populate temp with the file path of the WAV file            
  68.             Buffer.BlockCopy(wavFile.ToCharArray(), 0, temp, 0, 2 * wavFile.Length);
  69.  
  70.             fixed (char* lpszFileName = temp)
  71.             {
  72.                 _VoiceRec = new CM_VOICE_RECORDER();
  73.  
  74.                 _VoiceRec.hwndParent = _Hwnd;
  75.                 _VoiceRec.dwStyle = wndStyle.VRS_NO_MOVE | wndStyle.VRS_MODAL;
  76.                 _VoiceRec.cb = (int)Marshal.SizeOf(_VoiceRec);
  77.                 _VoiceRec.xPos = -1;
  78.                 _VoiceRec.yPos = -1;
  79.                 _VoiceRec.lpszRecordFileName = lpszFileName;
  80.             }
  81.         }
  82.  
  83.         // Show the voice recorder
  84.         public unsafe void Show()
  85.         {
  86.             fixed (CM_VOICE_RECORDER* _VoiceRecPtr = &_VoiceRec)
  87.             {
  88.                 _hRecorder = VoiceRecorder_Create(_VoiceRecPtr);
  89.             }
  90.         }
  91.     }
  92. }
  93. #endregion
  94.  
Nov 10 '08 #4
Cyprus106
31 New Member
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!
Nov 11 '08 #5
markmcgookin
648 Recognized Expert Contributor
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!
Nov 12 '08 #6
JamesGeddes
6 New Member
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
Dec 3 '09 #7
markmcgookin
648 Recognized Expert Contributor
do you definitely have

using System.Runtime. InteropServices ;

In your code? Is this running on a mobile device?

Cheers,

Mark
Dec 3 '09 #8
JamesGeddes
6 New Member
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
Dec 3 '09 #9
Dear markmcgookin,

This code help me a lot and i want to know is it possible to record sound in mp3 format.
Oct 14 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1953
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
6
1532
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
1
1695
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 -
1
5268
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...
2
2042
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
4
1908
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
2
64519
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”.
11
3222
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...
1
2288
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
0
9691
marktang
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...
0
9551
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,...
0
10505
Oralloy
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...
0
10276
jinu1996
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...
0
10035
tracyyun
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...
0
9090
agi2029
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...
0
5471
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...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.