Page 1 of 1

[unresolved] record with microphone

Posted: Mon Jun 29, 2015 10:23 am
by ittarter
Hi! I'm using windows 8, quicktime is installed, code is below but no file is created, or maybe it is but I'm not finding it? I assume it's saving to defaultfolder since I'm not doing audioclip (honestly I'd be happy to save it to the stack as a clip, whatever's easiest, I want it to be overwritten by every subsequent time a recording is made).

Here's my code, let me know what you think!

Code: Select all

on recordme # mouseup of Record Me button
   global gRecordOn
   if gRecordOn is false then
      put true into gRecordOn
      set the coloroverlay[opacity] of button "recordme" to "0" # visible indication of recording
      set the recordFormat to "aiff" 
      set the recordCompression to "raw"
      record sound file "currentprompt.aif" # self-recorded audio for user to listen to if desired
   else if gRecordOn is true then
      put false into gRecordOn
      set the coloroverlay[opacity] of button "recordme" to "150"
      stop recording
   end if
end recordme

on playme # Mouseup of Play Me button
   if URL("file:currentprompt.aif") is empty then
      answer "Microphone did not record."
   else
      play "currentprompt.aif"
   end if
end playme
Regards,

Ivan

Re: record with microphone

Posted: Mon Jun 29, 2015 1:25 pm
by Klaus
Hi Ivan,

a couple of things:
ittarter wrote:Hi! I'm using windows 8, quicktime is installed, code is below but no file is created, or maybe it is but I'm not finding it? I assume it's saving to defaultfolder since I'm not doing audioclip (honestly I'd be happy to save it to the stack as a clip, whatever's easiest, I want it to be overwritten by every subsequent time a recording is made).
You can only record to a file, not into a stack.
As a programmer you shoud not ASSUME, you need to KNOW! :D
So provide a correct pathname where you (and later your standalone!) will have write permission,
maybe -> specialfolderpath("documents")

Please read my comment in the script:

Code: Select all

on recordme # mouseup of Record Me button

   ## Create a valid file path and use that, so you will know where to find the sound!
   put specialfolderpath("documents") & "/currentprompt.aif" into tSoundFile
   global gRecordOn
   if gRecordOn is false then
      put true into gRecordOn

      ## Quotes:
      set the coloroverlay["opacity"] of button "recordme" to "0" # visible indication of recording
      set the recordFormat to "aiff" 

      ## The recordCompression is a four-character string! So you need to add a SPACE here:
      set the recordCompression to "raw "
      record sound file tSoundFile # self-recorded audio for user to listen to if desired
  end if

  ## I personally avoid nested else if then...
  if gRecordOn is true then
      put false into gRecordOn

     ## Quotes:
      set the coloroverlay["opacity"] of button "recordme" to "150"
      stop recording
   end if
end recordme

on playme # Mouseup of Play Me button
   put specialfolderpath("documents") & "/currentprompt.aif" into tSoundFile

   ## if URL("file:currentprompt.aif") is empty then
   ## Wrong usage of URL syntax, you need to check IF THERE IS A FILE XXX

   if there is NOT a file tSoundFile then
      answer "Microphone did not record."
   else

     ## Not sure if PLAY will work here (LC is VERY picky what sound formats to play!), if in doubt also use a player object here!
      play tSoundFile
   end if
end playme
Hope that helps!


Best

Klaus

Re: record with microphone

Posted: Tue Jun 30, 2015 10:50 am
by ittarter
Hi Klaus,

I was originally a bit unclear on how specialfolderpath works so I avoided using it for quite a while. Clearly it's time for me to add that to my vocabulary!

I understood that if I don't specify a folder, livecode applies defaultfolder -- Does it not do that? or not for certain commands like playing audio?

The quotes around opacity... I was following the dictionary and it used quotes for other coloroverlay properties but not that one.
## Wrong usage of URL syntax, you need to check IF THERE IS A FILE XXX
I tried that originally then changed it to see if the other would work, forgot to change it back :P

Thanks for the help! I'm going to try to learn how specialfolderpath works today and then apply your changes.

Re: record with microphone

Posted: Tue Jun 30, 2015 10:57 am
by ittarter
Also, what do you mean, nested if-then? That's synonymous to using else if? I thought that a nested if-then was executed if the first 'if' is true, not false.
IF the apple is green then
IF the apple is (also) big then
eat the apple
else
give green apple to baby
end if
else
give Roy the apple (he doesn't like green ones)
end if
Anyway, if the two if-thens are separate, both thens can be executed in the same instance. But in this case, that's exactly what I DON'T want to happen. If we use your two separate if-thens, the recording stops as soon as it starts.

Re: record with microphone

Posted: Tue Jun 30, 2015 11:36 am
by ittarter
I'm still not getting a soundfile created/recorded. When I record in Audacity it works fine so I know my microphone works (livecode doesn't need me to do anything to "load" the microphone, does it?) I've tried "desktop" and "documents". I tried two separate if-thens (which didn't work, as I predicted), then switched back to if-else if. After trying tSoundFile (which didn't work), since there are two separate commands, I switched to a global variable (gSoundFile) which still doesn't work.

Code: Select all

on recordme # mouseup of Record Me button
   global gRecordOn, gSoundFile
   put specialfolderpath("desktop") & "/currentprompt.aif" into gSoundFile
   if gRecordOn is false then
      put true into gRecordOn
      set the coloroverlay["opacity"] of button "recordme" to "0" # visible indication of recording
      set the recordFormat to "aiff"
      set the recordCompression to "raw "
      record sound file gSoundFile # self-recorded audio for user to listen to if desired
   else if gRecordOn is true then
      put false into gRecordOn
      set the coloroverlay["opacity"] of button "recordme" to "150"
      stop recording
   end if
end recordme

on playme # Mouseup of Play Me button
   global gSoundFile
   put specialfolderpath("desktop") & "/currentprompt.aif" into gSoundFile
   if there is not a file gSoundFile then
      answer "Microphone did not record."
   else
      play gSoundFile # if this doesn't work use a Player object 
   end if
end playme

Re: record with microphone

Posted: Tue Jun 30, 2015 1:02 pm
by Klaus
Hi Ivan,
ittarter wrote:Also, what do you mean, nested if-then? That's synonymous to using else if? I thought that a nested if-then was executed if the first 'if' is true, not false.
yes, sorry, avoiding nested (and thus les readable) IF THEN ELSE IF THEN stuff is just my personal preference. :D
ittarter wrote:Anyway, if the two if-thens are separate, both thens can be executed in the same instance. But in this case, that's exactly what I DON'T want to happen. If we use your two separate if-thens, the recording stops as soon as it starts.
Yes, my fault I forgot an important line in my example script:

Code: Select all

on recordme # mouseup of Record Me button

   ## Create a valid file path and use that, so you will know where to find the sound!
   put specialfolderpath("documents") & "/currentprompt.aif" into tSoundFile
   global gRecordOn
   if gRecordOn is false then
      put true into gRecordOn

      ## Quotes:
      set the coloroverlay["opacity"] of button "recordme" to "0" # visible indication of recording
      set the recordFormat to "aiff" 

      ## The recordCompression is a four-character string! So you need to add a SPACE here:
      set the recordCompression to "raw "
      record sound file tSoundFile # self-recorded audio for user to listen to if desired

      ## THIS ONE:
      EXIT RECORDME
  end if

  ## I personally avoid nested else if then...
  if gRecordOn is true then
      put false into gRecordOn
...
Hmmm, your script looks OK, you should check for eventual errors in any case:

Code: Select all

on recordme # mouseup of Record Me button
   global gRecordOn, gSoundFile
   put specialfolderpath("desktop") & "/currentprompt.aif" into gSoundFile
   if gRecordOn is false then
      put true into gRecordOn
      set the coloroverlay["opacity"] of button "recordme" to "0" # visible indication of recording
      set the recordFormat to "aiff"
      set the recordCompression to "raw "
      record sound file gSoundFile # self-recorded audio for user to listen to if desired
     
     ## Check right here:
     if the result <> empty then
       answer "ERROR!" & CR & the result
       exit recordme
    end if
    ## If you see the answer dialog, please tell us what it reads!

   else if gRecordOn is true then
      put false into gRecordOn
      set the coloroverlay["opacity"] of button "recordme" to "150"
      stop recording
   end if
end recordme

on playme # Mouseup of Play Me button
   global gSoundFile

   ## This line make the GLOBAL declaration unneccessary! :-)
   put specialfolderpath("desktop") & "/currentprompt.aif" into gSoundFile
...
Hope that helps!


Best

Klaus

Re: record with microphone

Posted: Wed Jul 01, 2015 10:26 am
by ittarter
Hi Klaus,

I can't get an error message, unfortunately, or I would pass it on to you. Any idea why I can't get an error message?

In the message box, if I enter "set the recordFormat to "aiff"; set the recordCompression to "raw "; record sound file gSoundFile; if the result <> empty then; answer "ERROR!" & CR & the result; end if" into the message box, the text briefly highlights but no response; I say aloud "Testing, Testing 1-2-3" or whatever; I enter "Stop recording" then "Play gSoundFile", and it says, No data in audioclip.

Code: Select all

on recordme
   global gSoundFile
   put specialfolderpath("desktop") & "/currentprompt.aif" into gSoundFile
   set the coloroverlay["opacity"] of button "recordme" to "0" # visible indication of recording
   set the recordFormat to "aif"
   set the recordCompression to "raw "
   record sound file gSoundFile
   if the result <> empty then
      answer "ERROR!" & CR & the result
   end if
end recordme

on stoprecording
      set the coloroverlay["opacity"] of button "recordme" to "150"
      stop recording
end stoprecording

on playme # Mouseup of Play Me button
   global gSoundFile
   put specialfolderpath("desktop") & "/currentprompt.aif" into gSoundFile
   if there is not a file gSoundFile then
      answer "Microphone did not record."
   else
      play gSoundFile
   end if
end playme

Re: [unresolved] record with microphone

Posted: Wed Jul 15, 2015 1:42 pm
by kroka
Hello ittarter,

sorry, I read this post a bit late.

What you are experiencing is a serious bug in LiveCode 7.

Fact is: It's simply not possible to record sound in LiveCode 7. Not in Windows, not on Mac. While recording, there is a temp file created, but in the end no soundfile comes up.

I reported this bug months ago. ( http://quality.runrev.com/show_bug.cgi?id=15321 )

The bug was confirmed and somebody seems to have dealt with it - but in the latest update 7.0.6 it was still not corrected.

I didn't find any workaround (other than doing it in LiveCode 6, where it still works, but because of other bugs, it is not possible to convert my whole project back to LC6).

So I am quite angry about this. It is blocking a huge and important project I have been working on for a long time now. The only workaround I could come up with is to create the recording module of my project in LC6 and call this from the other project as standalone. But that is not elegant at all and has its limitations.

Does anybody know a way to record a sound file in LiveCode 7 (please no links to any introduction how to record a sound file - this is just not working in LC7).

I would appreciate that very much!

Kroka

Re: [unresolved] record with microphone

Posted: Wed Jul 15, 2015 3:58 pm
by jacque
Add a comment to your bug report, which will bring it to the attention of the team. It looks to me like the pull request may not have been noticed and so the fix hasn't been merged yet. I believe the team recently reorganized the github branches and this fix may have been lost.