element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Automatic audio recording question...
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 4 replies
  • Subscribers 674 subscribers
  • Views 1168 views
  • Users 0 members are here
  • raspberry_pi
  • raspeberry_pi_accessories
Related

Automatic audio recording question...

Former Member
Former Member over 11 years ago

I'm building an automated audio recording system - and was wondering if I could get some advice...

 

My question in a nutshell: I need to run arecord, while also doing other things, then stop arecord at a specified time. I want to be able to check what it is doing as well (to make sure it is recording when it should be). How would I kick this off from a python or php script, and how would I check on the status? Would the php (or python) script 'wait' while arecord was running?

 

Background:

 

I have the Pi+Wolfson Audio card working. I desoldered the 2x13 pin header and replaced it with a stacking header (it isn't easy!). I have a RTC (no internet in location) and OLED display using the I2C bus. Eventually I'll have some sort of Pi UPS hooked up to the Pi to allow for a graceful power off, and a wifi adapter (Ad-hoc mode) to remotely manage it, possibly a GPIO expansion board (I2C) to get button inputs.

 

However, I'm struggling a little on the software side of things. I'm new to python, don't do too much bash/shell scripting. I'm much more comfortable with php. My application has a "few" parts:

 

Schedule (would be stored in a MySQL DB)

Web front-end to view files on the Pi, and do some operations (probably php).

Some way to control OLED (calling python scripts)

Some way to start and stop recording scripts

 

Originally, I figured I'd hardcode when to start/stop recording, via a CRON job. However, I've decided to make it more complex (hurray!), hence the setup described above...

 

Thanks,

 

John

  • Sign in to reply
  • Cancel
  • Former Member
    Former Member over 11 years ago

    Perhaps you could implement this as a shell script running as a daemon. You can output a log in real time which you could format nicely as a web page to do your monitoring. If I understand you correctly, and you don't have internet access, just hook the pi up to a home network to monitor status and control recording etc (e.g. control the script over ssh until you get some buttons working on the GPIO). If you're familiar with C at all, I recall it being pretty straight forward to control a C program over UART on the pi. You could, for example, run the C program as a daemon checking for UART input and when that input is detected, fork and call arecord.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago

    Thanks - I briefly contemplated writing something in C... I may end up rewriting the python portions in C if I run into any limitations with a GPIO expander. I ended up doing the following (still working on it):

     

    Added apache to the sudoers file (note: this device won't be internet-connected, though the Pi will be running as an ad-hoc access point, but this is not recommended for security reasons)

     

    Created a few php files:

     

    This is my start_recording script:

     

    function run_in_background($command) {
      shell_exec('sudo bash -c "exec nohup setsid ' . $command . ' > /dev/null 2>&1 &"');
    }
    
    $filename = date('Y_m_d-H_i') . '.wav';
    $arecord = '/usr/bin/arecord -Dhw:0 -r 44100 -c 2 -f S16_LE /var/www/recordings/' . $filename;
    
    // Run arecord in background
    run_in_background($arecord);
    
    $python = 'sudo python /home/pi/Adafruit_Python_SSD1306/examples/monitor_recordings.py';
    
    // Run python in the backgroun
    run_in_background($python);

     

    By running shell_exec like above, arecord won't 'lock' the php page up from exiting.

     

    I also have a stop_recording script:

     

    exec('ps aux | grep \'^root.\{1,\}arecord\' | perl -pe \'$_ = join(",", split /\s+/, $_, 11)\'', $output);
    
    
    foreach ($output as $value) {
      $temp_arr = str_getcsv($value);
      shell_exec('sudo kill -s SIGINT ' . $temp_arr[1]);
    }
    
    
    
    
    exec('ps aux | grep \'^root.\{1,\}monitor_recordings\' | perl -pe \'$_ = join(",", split /\s+/, $_, 11)\'', $output);
    
    
    foreach ($output as $value) {
      $temp_arr = str_getcsv($value);
      shell_exec('sudo kill -s SIGINT ' . $temp_arr[1]);
    }
    
    
    shell_exec('sudo python /home/pi/Adafruit_Python_SSD1306/examples/clear.py');

     

    The python code handles displaying recording metadata to an I2C connected OLED.

     

    To handle the scheduling, I think I'll run a CRON job that curl's a php page that checks a MySQL DB and the status of arecord.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    Very cool stuff. I appreciate you coming back posting an update of the status of your project as it provides me with ideas I had never thought of for a project of my own (I also see that you were further into details than I realized and I apologize for my vague response).

     

    I'm working on a similar project trying to tie in with Musicbrainz to pull metadata to add to the recordings (Youtube, Pandora, internet radio, vinyl, cassette etc.).

     

     

    I have a few questions of curiosity:

     

    If you don't mind me asking, what source are you recording?

     

    What sort of data are you outputting to the OLED? Output from arecord?

     

    Also, from what I gather the recordings are all to kick off and end at a certain time based on your scheduling data. Is that correct?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 11 years ago in reply to Former Member

    If you don't mind me asking, what source are you recording?

     

    Sermons during mass. I was unable to find a schedulable recorder under $2000, though maybe something exists that I missed. I toyed with the idea of using a security system DVR, but didn't see any units that I liked.

     

    What sort of data are you outputting to the OLED? Output from arecord?

    Right now:

    REC

    Filename.wav

    Time: mm:ss

    arecord pid (debugging purposes)

     

    Eventually I'll make a bar that shows how much disk space is used / free.

     

    Also, from what I gather the recordings are all to kick off and end at a certain time based on your scheduling data. Is that correct?

     

    Yes.

     

     

    Now that I have this part worked out, I need to add a USB jump drive. My ultimate goal is to have the SD be read only, and have it do all audio writes to a USB drive.

     

    John

    http://www.element14.com/community/thread-branch!input.jspa?message=123463

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube