Recording audio on Windows

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
dalkin
Posts: 100
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Recording audio on Windows

Post by dalkin » Sat May 02, 2020 5:25 am

Topic moved from the Windows platform-specific board.

I have been struggling to get a stack to record audio on the Windows platform. This is as far as I can get trying to interpret the dictionary settings but as it is writ, it's causing LC 9.6.0 (DP4) Indy to crash. Any help appreciated.

Code: Select all

on mouseUp
   put the cUserDefinedRecordingFolder of this card into tUserFolder
   
   ## User did not define a folder yet:
   if there is not a folder tUserFolder then
      answer folder "Select a folder for the recordings:"
      if the result is cancel then
         exit to top
      end if
      ## We store the folder also in a custom property:
      set the cUserDefinedRecordingFolder of this stack to IT
      
      ## We need this in this script:
      put it into tUserFolder
   end if
   
   set the recordFormat to "wav"
   ask "Please name the recording:"
   if it = empty then
      exit to top
   end if
   put it into tUserDefinedName
   put tUserFolder & "/" & tUserDefinedName & ".wav" into tFile
   cameraControlCreate "MyCamera"
   cameraControlSet "MyCamera", "audioDevice", "default"
   cameraControlDo "MyCamera", "startRecording", tFile
end mouseUp
If you're skating on thin ice you might as well dance.

livecodeian
Posts: 10
Joined: Mon Apr 22, 2013 3:29 pm
Location: Edinburgh
Contact:

Re: Recording audio on Windows

Post by livecodeian » Mon May 04, 2020 2:28 pm

Hi dalkin, the crash you've encountered has been reported here - https://quality.livecode.com/show_bug.cgi?id=22580

As stated in the report, the crash happens when recording from a cameraControl that has not been made visible.

There is a way you can work around this bug until it has been fixed - add the following line to your script before starting the recording:

Code: Select all

cameraControlSet "MyCamera", "visible", true
Note that although the control is made visible, as the default rect of the control has zero width and height it won't display on the screen when recording


--
Ian Macphail, LiveCode Ltd.
Ian Macphail, LiveCode Ltd.

livecodeian
Posts: 10
Joined: Mon Apr 22, 2013 3:29 pm
Location: Edinburgh
Contact:

Re: Recording audio on Windows

Post by livecodeian » Mon May 04, 2020 2:31 pm

I should add that on Windows the output format from the cameraControl is always Windows Media Video (WMV) or Windows Media Audio (WMA). The recordFormat property and the output filename extension have no bearing on this.

--
Ian Macphail, LiveCode Ltd.
Ian Macphail, LiveCode Ltd.

dalkin
Posts: 100
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Recording audio on Windows

Post by dalkin » Tue May 05, 2020 8:48 am

Thank you for engaging with this issue Ian. Adding that line doesn't work I'm afraid, no file is produced, but I can only think that the syntax on the stopRecording button is faulty. Unfortunately the dictionary doesn't shed any light on 'stopRecording' (references Mac and Android only). The code for my button to stop recording is:

Code: Select all

on mouseUp
cameraControlDo "MyCamera", "stopRecording"
cameraControlDelete "MyCamera"
put the result into tFile
end mouseUp
the code to enable recording, including the line you recommended, looks like this:

Code: Select all

on mouseUp
   put the cUserDefinedRecordingFolder of this card into tUserFolder
   
   ## User did not define a folder yet:
   if there is not a folder tUserFolder then
      answer folder "Select a folder for the recordings:"
      if the result is cancel then
         exit to top
      end if
      ## We store the folder also in a custom property:
      set the cUserDefinedRecordingFolder of this stack to IT      
      ## We need this in this script:
      put it into tUserFolder
   end if
   
   set the recordFormat to "WMA"
   ask "Please name the recording:"
   if it = empty then
      exit to top
   end if
   put it into tUserDefinedName
   put tUserFolder & "/" & tUserDefinedName & ".WMA" into tFile
   
   ## Now set two custom properties fo the PLAY1 button, so the button knows what to play when clicked!
   set the cAudioFile of btn "play1" to tFile
   set the filename of player "P1" to tFile
   set the cUserDefinedName of btn "play1" to tUserDefinedName
   cameraControlCreate "MyCamera"
   cameraControlSet "MyCamera", "audioDevice", "default"
   cameraControlSet "MyCamera", "visible", true
   cameraControlDo, "MyCamera", "startRecording", "tUserDefinedName"
   set the label of button "Record1" to "Recording"
   set the backgroundcolor of button "Record1" to orange
   ##
   
end mouseUp
Last edited by dalkin on Tue May 05, 2020 10:31 am, edited 1 time in total.
If you're skating on thin ice you might as well dance.

livecodeian
Posts: 10
Joined: Mon Apr 22, 2013 3:29 pm
Location: Edinburgh
Contact:

Re: Recording audio on Windows

Post by livecodeian » Tue May 05, 2020 10:16 am

Hi dalkin, your "stopRecording" code looks ok to me, maybe check the tFile value you're passing to

Code: Select all

cameraControlDo "MyCamera", "startRecording", tFile
is valid, and is within a folder that exists and can be written to.

--
Ian Macphail, LiveCode Ltd.
Ian Macphail, LiveCode Ltd.

dalkin
Posts: 100
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Recording audio on Windows

Post by dalkin » Tue May 05, 2020 10:32 am

Ian, we passed like ships in the night. The default folder is set as in the code and is writeable. I have checked as much as I can. Nothing I do seems to work.
If you're skating on thin ice you might as well dance.

livecodeian
Posts: 10
Joined: Mon Apr 22, 2013 3:29 pm
Location: Edinburgh
Contact:

Re: Recording audio on Windows

Post by livecodeian » Wed May 06, 2020 11:32 am

Hi dalkin, i spotted a mistake in your setup code:

Code: Select all

cameraControlDo, "MyCamera", "startRecording", "tUserDefinedName"
Here you've used a variable name in quotes, which will send the name of the variable to cameraControlDo instead of the contents of the variable, though it looks from the rest of your code like the variable should be tFile instead:

Code: Select all

cameraControlDo, "MyCamera", "startRecording", tFile
Also, if you're going to play back the file in a player control you should wait until the recording has stopped before setting the filename of the player as it will attempt to load the file when you do that, which will fail if the file doesn't exist yet!

--
Ian Macphail, LiveCode Ltd.
Ian Macphail, LiveCode Ltd.

dalkin
Posts: 100
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Recording audio on Windows

Post by dalkin » Thu May 07, 2020 9:56 am

I'm hopelessly out of my depth getting this to work. If you can set me on the right path I can only imagine it will be of benefit to the whole community as there doesn't appear to be a step-by-step process anywhere. Obviously stitching the dictionary entries with the right variables is the path to happiness but I just can't get it right. I have attached a sample stack with 3 buttons, 'Record', 'Stop' and 'Play' along with a player object to scrub potentially long sounds.
sample.zip
(1.74 KiB) Downloaded 13 times
If you're skating on thin ice you might as well dance.

dalkin
Posts: 100
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Recording audio on Windows

Post by dalkin » Fri May 22, 2020 11:36 pm

It has finally been sorted .. the difficulties were linked, in part, to a bug. See https://quality.livecode.com/show_bug.cgi?id=22739 The other problem was due to my fat thumbs and hunt-n-peck typing but we won't go into that. The attached stack should record audio on Windows. As I type, I have noticed an update to RC2 but I don't know whether the issue was fixed in that release.
Attachments
Windows Audio Demo.livecode.zip
(1.86 KiB) Downloaded 8 times
If you're skating on thin ice you might as well dance.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”