Now tested on the latest OSX 10.12.3 Sierra on a(n) MBP and iMac.
And it is still working - WOOHOO.
The code now has some error checking and commented out code for a "path" option instead of just "tmp" alone.
It is bash centric but should work fine on ksh(93)...
Code:
#!/bin/bash
# Usage:- [./]AUDIO_CAPTURE.sh <number_of_seconds_from_1_upwards><CR>
#
# This DEMO shell script uses a virgin OSX Sierra install only, nothing else is required.
# The conversion for this DEMO is mono, 8 bit, unsigned integer at 48000 sps but it is
# easy to convert to just about anything, 'man afconvert'...
#
# This creates a sample which is then saved to '/"$POSIXpath"/Untitled.m4a' which is then converted
# to '/"$POSIXpath"/Untitled.wav' file. Both formats are then played using 'afplay'.
#
# From the current directory, './AUDIO_CAPTURE.sh 5<CR>' gives about 5 seconds of recording.
#
# Use the internal built in microphone as a test.
# Time for the recording.
seconds="$1"
# Some very basic error checking.
case $seconds in
''|*[!0-9]*) seconds=1 ;;
esac
if [ "$seconds" = "" ] || [ "$seconds" -le "1" ]
then
seconds=1
fi
POSIXpath="tmp"
# 'POSIXpath' should be in POSIX format.
# E.G. 'Users/myhome/Desktop'. There is no need for leading and trailing backslashes - see below.
# This could be a command line second argument but is NOT given '$2' in this DEMO.
# When the section below is uncommented...
# Usage:- [./]AUDIO_CAPTURE.sh <number_of_seconds_from_1_upwards> [your/path/to]<CR>
# Where [your/path/to] is optional and defaults to "tmp".
#
# POSIXpath=$2
# Error check for directory existence.
# if [ ! -d "/$POSIXpath/" ]
# then
# POSIXpath="tmp"
# fi
# Convert to AppleScript format for this code.
OSXpath="${POSIXpath////:}"
SAMPLE()
{
: > /"$POSIXpath"/Untitled.m4a
chmod 666 /"$POSIXpath"/Untitled.m4a
osascript << AppleSampler
tell application "QuickTime Player"
activate
set savePath to "Macintosh HD:" & "$OSXpath" & ":Untitled.m4a"
set recording to new audio recording
set visible of front window to false
delay 2
start recording
delay "$1"
stop recording
export document "Untitled" in file savePath using settings preset "Audio Only"
close (every document whose name contains "Untitled") saving no
tell application "System Events" to click menu item "Hide Export Progress" of menu "Window" of menu bar 1 of process "QuickTime Player"
delay 1
quit
end tell
AppleSampler
# 'wait' added for fullness only.
wait
}
# Use the function to create a _background_ recording.
SAMPLE "$seconds"
# Example of conversion to a WAVE file.
afconvert -f 'WAVE' -c 1 -d UI8@48000 /"$POSIXpath"/Untitled.m4a /"$POSIXpath"/Untitled.wav
ls -l /"$POSIXpath"/Untitled.*
# Playback both files.
afplay /"$POSIXpath"/Untitled.m4a
sleep 1
afplay /"$POSIXpath"/Untitled.wav
exit 0
i am having a weird error on mac os x running some shell scripts. i am a complete newbie at this and this question concerns 2 scripts. one of which a friend of mine wrote (videochecker.sh) a couple weeks ago and it's been running fine on another machine.
then last week i wrote capture.sh and it... (2 Replies)
I want to config Transparent Proxy using Shell Script.
I have more questions<exercise of me :D>:
+ Check that the squid is installed or not install and version is installed
+Allows users to choose to run a transparent proxy or not
+Perform configuration and turn on service in accordance... (0 Replies)
Hello,
I am new to Mac OSX and shell scripting all together. I was wondering if anyone could help get me started in a few scenarios so that I would be able to automate checking a system against a STIG checklist. A STIG Checklist is a DoD Guideline for securing systems. Here is the first... (3 Replies)
I'm trying to record audio using Audacity 2.0.5 installed from SlackBuilds. My system is 64-bit Slackware 14.1 and a sound card is Intel HD Audio. I didn't change my sound system to OSS. (Default sound system in Slackware 14.1 is ALSA, isn't it?) First, I set Internal Microphone slider in KMix... (2 Replies)
Hi,
I want 10000+ unique Audio file of approx 2MB each. How can i generate numerous audio files using shell script. Any tool, command or suggestions are welcome.
If i give one audio seed file then can we create numerous unique files with same seed file?
Any help is highly appreciable.... (11 Replies)
Hi everyone...
I don't know if this is the correct forum but it is Apple OSX specific.
It is a proper pseudo-man page for the sparse official one...
This is as thorough as experimentation can get...
Command line afplay, August 2016.
---------------------------------
afplay -h
... (0 Replies)
This is a DEMO shell script to generate a simple graticule and plot inside it...
Apologies for any typos...
it is another building block along with my other two shell uploads recently to start a semi_serious project of an Terminal_AudioScope...
The fist upload I posted recently was to show... (83 Replies)
Hello everyone!
I'm developing a MacOs Application in python and I'm having some issues trying to find information related to the power button pressed event. I know that in Ubuntu 14.04 you can find information about it on the acpi folders, but I realized that here in Mac that process is... (0 Replies)
Hello,
I have a backup script that runs an rsync backup to an external drive. I use the script frequently on Windows and Linux and have installed it on a Mac. The script has an option to run shutdown after the backup has completed. Since backup can take hours to run, this is an option that is... (10 Replies)
Discussion started by: LMHmedchem
10 Replies
LEARN ABOUT REDHAT
time
TIME(2) Linux Programmer's Manual TIME(2)NAME
time - get time in seconds
SYNOPSIS
#include <time.h>
time_t time(time_t *t);
DESCRIPTION
time returns the time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds.
If t is non-NULL, the return value is also stored in the memory pointed to by t.
RETURN VALUE
On success, the value of time in seconds since the Epoch is returned. On error, ((time_t)-1) is returned, and errno is set appropriately.
ERRORS
EFAULT t points outside your accessible address space.
NOTES
POSIX.1 defines seconds since the Epoch as a value to be interpreted as the number of seconds between a specified time and the Epoch,
according to a formula for conversion from UTC equivalent to conversion on the naive basis that leap seconds are ignored and all years
divisible by 4 are leap years. This value is not the same as the actual number of seconds between the time and the Epoch, because of leap
seconds and because clocks are not required to be synchronised to a standard reference. The intention is that the interpretation of sec-
onds since the Epoch values be consistent; see POSIX.1 Annex B 2.2.2 for further rationale.
CONFORMING TO
SVr4, SVID, POSIX, X/OPEN, BSD 4.3
Under BSD 4.3, this call is obsoleted by gettimeofday(2). POSIX does not specify any error conditions.
SEE ALSO ctime(3), date(1), ftime(3), gettimeofday(2)Linux 2.0.30 1997-09-09 TIME(2)