using MCISendString to record

Signe Marie Sanne Signe.Sanne at
Thu Mar 31 02:28:13 EST 2005

I am still waiting to get the key to be able to upload a small stack to 
RevOnLine. While waiting I have extracted all the scripts. Many of them have 
been adapted from a stack by Tom McCarthy, St. Catalina Girls School, 
Matsuyama, Japan:

on react
   move target rel 1,1
   wait 10 ticks
   move target rel -1,-1
end react

---------------------------Disables QT:
on mouseUp
   set dontUseQT to true
   get the dontUseQT
   if true then answer "QT is not in use"
   else answer "QT is still in use"
end mouseUp

--------------------Check if mciSendString is installed:

on sjekkeMCI
   put "This computer probably lacks recording options." into line 1 of temp
   put "Check the presence of Windows Multimedia Tools." into line 2 of temp

   put "This can be done by searching for the file 'mciwave.drv'." into line 
3 of temp
   put "More info about 'mciSendString': " into line 5 of temp
into line 7 of temp
   put temp into svar
   put specialfolderpath("system") into t
   put "/system/mciwave.drv" after t
   if there is not file t then answer svar
     --Lists all devices:
     put mciSendString("sysinfo all quantity") into xMax
     #put empty into fld "deviceNames"
     put empty into tDeviceNames
     repeat with x = 1 to xMax
       put "sysinfo all name" && x into commandString
       # put mciSendString(commandString) & return after fld "deviceNames"
       put mciSendString(commandString) & return after tDeviceNames
     end repeat
     #answer tDeviceNames
     if "WaveAudio" is not in tDeviceNames then answer svar
     else  answer "Windows Multimedia Tools is available."
   end if
end sjekkeMCI

----------------Finds the folder in which you store the audiofile
----------------and gives it a name

on mouseUp

   global tFile  --short name of the file, for instance "mySound.wav"
   global tLongPath --long name of file:"C:/.../.../SoundFolder/"mySound.wav"

   answer folder "Save into which folder:"
   if it is empty or the result is "Cancel" then exit mouseUp
   put it into tFolder
   ask "Save as wave file:" with "----.wav"
   if it is empty or the result is "Cancel" then exit mouseUp
   put it into tFile
   put tFolder & "/" & tFile into tLongPath
   answer tLongPath
end mouseUp

function myMCI tstring
   put mciSendString(tstring) into returnValue
   get the result
   if the result is not empty then
     return "error"
     return returnValue
   end if
end myMCI

-------------------------Records the sound:
on RecordAudio

   global tFile

   put 1500 into max_time
   get mcirecord(tFile, max_time)
end RecordAudio

function mcirecord tFile, max_time
   get mymci("close myaudio")
   put "open new type waveaudio alias myaudio" into tstring
   get myMCI(tstring)
   if it is "error" then
     return "error -- opening part"
     exit mcirecord
   end if

   get mymci("set myaudio time format milliseconds")
   if mymci("record myaudio") is not empty then
     get mymci("close all")
     return "error -- record part"
     exit mcirecord
   end if

end mcirecord

---------------------- Stops and saves the audio file to disk
on stopRecording

   global tLongPath

   get mymci("stop")
   put "save myaudio " & quote & tLongPath & quote into x
   get mymci(x)
   return it
end stopRecording

--------------------------Plays the audio file with mciSendString
on listen
   global tFile, tLongPath

   if there is a file tLongPath then get playmysound(tFile)
end listen

function playmysound tFile
   get myMCI("close myaudio")
   put "open"&& quote& tLongPath & quote&& "type waveaudio alias myaudio" 
into tstring
   get myMCI(tstring)
   put myMCI("status myaudio length") into ttime
   if ttime is "error" or ttime is not a number then
     put 0 into ttime
     return ttime
   end if
   if myMCI("play myaudio from 0") is "error" then
     return 0
   end if
   return ttime
   put ttime
end playmysound

----------------------------- Stops playing the audio file:
on stopPlaying
   get myMCI("close myaudio")
end stopPlaying

More information about the Use-livecode mailing list