Saving recorded sound file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Saving recorded sound file
I'm building a Mac standalone that follows a splash stack (Loader) and presents users with an option to clone a stack that holds various items of entered text and saves the field entries. It works as expected (and works well might I add) But on each cloned card, I want to present the user with an option to record up to 5 snippets of audio. Each snippet should ideally be named by the user and saved at a location chosen by the user, then the Play button should play the audio. So the problem I can't solve is giving each recording the name chosen by the user and using the Play button to find it and play it.
This is as far as I've got so any advice would be welcomed. Unfortunately, there doesn't seem to be any definitive guide for recording audio in standalones, I have been told that if I want to record audio on a Windows standalone I'll be looking at using this:
##
In Indy and above, you can use the Advanced Camera Controls to do audio
recording on Windows. Something like:
cameraControlSet tCameraControlName, "videoDevice", empty
cameraControlDo tCameraControlName, "startRecording",
specialFolderPath("documents") & "/video.mp4"
##
Record button:
on mouseUp
set the recordFormat to "wav"
mergMicrophoneStartRecording audio1
set the label of button "Record1" to "Recording"
end mouseUp
Stop Recording button:
on mouseUp
mergMicrophoneStopRecording
set the label of button "Record1" to "Record1"
end mouseUp
Play button
on mouseUp
play audio.wav
set the label of button "Play1" to "Playing"
wait until the sound is done
set the label of button "Play1" to "Play1"
end mouseUp
This is as far as I've got so any advice would be welcomed. Unfortunately, there doesn't seem to be any definitive guide for recording audio in standalones, I have been told that if I want to record audio on a Windows standalone I'll be looking at using this:
##
In Indy and above, you can use the Advanced Camera Controls to do audio
recording on Windows. Something like:
cameraControlSet tCameraControlName, "videoDevice", empty
cameraControlDo tCameraControlName, "startRecording",
specialFolderPath("documents") & "/video.mp4"
##
Record button:
on mouseUp
set the recordFormat to "wav"
mergMicrophoneStartRecording audio1
set the label of button "Record1" to "Recording"
end mouseUp
Stop Recording button:
on mouseUp
mergMicrophoneStopRecording
set the label of button "Record1" to "Record1"
end mouseUp
Play button
on mouseUp
play audio.wav
set the label of button "Play1" to "Playing"
wait until the sound is done
set the label of button "Play1" to "Play1"
end mouseUp
If we're treading on thin ice, well you might as well dance.
Re: Saving recorded sound file
Hi dalkin,
some hints:
In your own interest get used to put QUOTES around (file- and object) names:
To be sure you are allowed to write to file use:
recording1 TAB user defined name 1 TAB filename of recording
recording2 TAB ...
recording3 TAB...
Get the picture?
Since you numbered your button names it will be easy to know which line of the "table" to access!
You can later save that info to a simple textfile and load it again when the app starts up the next time.
Best
Klaus
some hints:
In your own interest get used to put QUOTES around (file- and object) names:
Code: Select all
...
mergMicrophoneStartRecording "audio1"
...
play "audio.wav"
...
Code: Select all
...
ask "Please name the recording:"
if it = empty then
exit to top
end if
put it into tUserDefinedName
## Now save this in the below mentioned "table"...
mergMicrophoneStartRecording (specialfolderpath("documents") & "/audio1.wav")
...
Use a global variable or custom property and manage the recordings in a little "table" (= tab and CR delimited text) like this:So the problem I can't solve is giving each recording the name chosen by the user and using the Play button to find it and play it.
recording1 TAB user defined name 1 TAB filename of recording
recording2 TAB ...
recording3 TAB...
Get the picture?
Since you numbered your button names it will be easy to know which line of the "table" to access!
You can later save that info to a simple textfile and load it again when the app starts up the next time.
Best
Klaus
Re: Saving recorded sound file
I'm sorry Klaus but I don't understand where a table comes into it. The 3 buttons are now showing as follows but nothing is recorded and nothing is saved:
Record button:
on mouseUp
set the recordFormat to "wav"
ask "Please name the recording:"
if it = empty then
exit to top
end if
put it into tUserDefinedName
## Now save this in the below mentioned "table"...
mergMicrophoneStartRecording (specialfolderpath("desktop") & "/audio.wav")
set the label of button "Record1" to "Recording"
end mouseUp
Stop Recording button:
on mouseUp
mergMicrophoneStopRecording
set the label of button "Record1" to "Record1"
end mouseUp
Play button
on mouseUp
play audio.wav
set the label of button "Play1" to "Playing"
wait until the sound is done
set the label of button "Play1" to "Play1"
end mouseUp
Record button:
on mouseUp
set the recordFormat to "wav"
ask "Please name the recording:"
if it = empty then
exit to top
end if
put it into tUserDefinedName
## Now save this in the below mentioned "table"...
mergMicrophoneStartRecording (specialfolderpath("desktop") & "/audio.wav")
set the label of button "Record1" to "Recording"
end mouseUp
Stop Recording button:
on mouseUp
mergMicrophoneStopRecording
set the label of button "Record1" to "Record1"
end mouseUp
Play button
on mouseUp
play audio.wav
set the label of button "Play1" to "Playing"
wait until the sound is done
set the label of button "Play1" to "Play1"
end mouseUp
If we're treading on thin ice, well you might as well dance.
Re: Saving recorded sound file
I thought your only problem is to assign the user given name to the appropriate recording?The 3 buttons are now showing as follows but nothing is recorded and nothing is saved:
I do not yet see where the user defined name comes into play however, where do you want to display them?
Re: Saving recorded sound file
Or use another approach with custom properties like this:
Button "record1"
Stop Recording button:
Play button
If you want to name the recorded file with the user defined name use this in the RECORD buttons:
Button "record1"
Code: Select all
on mouseUp
set the recordFormat to "wav"
ask "Please name the recording:"
if it = empty then
exit to top
end if
put it into tUserDefinedName
put specialfolderpath("desktop") & "/audio1.wav" 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 cUserDefinedName of btn "play1" to tUserDefinedName
mergMicrophoneStartRecording tFile
set the label of button "Record1" to "Recording"
end mouseUp
Code: Select all
on mouseUp
mergMicrophoneStopRecording
set the label of button "Record1" to "Record1"
end mouseUp
Code: Select all
on mouseUp
put the cAudioFile of me into tFile
put the cUserDefinedName of me into tUserDefinedName
if tFile = EMPTY then
## Nothing recorded yet!
exit to top
end if
answer "Now playing:" && tUserDefinedName
play tFile
set the label of button "Play1" to "Playing"
wait until the sound is done
set the label of button "Play1" to "Play1"
end mouseUp
Code: Select all
...
put it into tUserDefinedName
put specialfolderpath("desktop") & "/" & tUserDefinedName & ".wav" into tFile
...
Re: Saving recorded sound file
That is so cool, Klaus. I would never have got there. Just 2 questions, is there a way for the user to define what the specialfolderpath is and change the generic "audio1" to the user's choice of name? Could I also suggest that you bring this conversation to the attention of the LC team because cross-platform audio recording (which was due to be a major part of LC9) is still part of the roadmap and seems to be scheduled for future development.
If you ever make it to Sydney, please let me know and I will fill you with beer.
If you ever make it to Sydney, please let me know and I will fill you with beer.
If we're treading on thin ice, well you might as well dance.
Re: Saving recorded sound file
Hi dalkin,
I doubt however that I will ever make if to Sydney in this life, but thanks anyway.
And I literally never FRET, see my bass on mybass page: https://major-k.de/bass/index.html
Best
Klaus
P.S.
You can of course use shorter names for your custom properties!
sure, check if the user already defined a folder for the recordings and ask him if not:is there a way for the user to define what the specialfolderpath is?
Code: Select all
on mouseUp
put the cUserDefinedRecordingFolder of this stack into tUserFolder
## User did not define a folder yet:
if tUserFolder = EMPTY then
answer folder "Select a folder for the recordings:"
if it = EMPTY 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
...
Although it might not look like this, but I am only a user of LC and not related nor related by marriage to the LC company.Could I also suggest that you bring this conversation to the attention of the LC team...
I doubt however that I will ever make if to Sydney in this life, but thanks anyway.
And I literally never FRET, see my bass on mybass page: https://major-k.de/bass/index.html
Best
Klaus
P.S.
You can of course use shorter names for your custom properties!