As an addendum to my Python freebie code below...

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

As an addendum to my Python freebie code below...

Postby Bazza » Fri Oct 01, 2010 7:25 pm

Hi all...

I mentioned at the end if it was possible to create a real time
audio oscilloscope and the answer seems to be YES. WOW!!!

Now I would like some help from the Linux geeks on here...

The code below is STANDARD Python, (2.5.2), and records
sound from the mic input at the moment.

Only a default Python install is required - no special
dependancies.

It takes about 8 seconds to record then after that it
immediately plays back the recording.

Would you give it a test. You might need to raise your
voice into the mic but hey that is no big deal.

Name the code below as record.py and save in the Python`s Lib drawer. As soon as you "import record[RETURN/ENTER]"
talk loudly into the mic for about 8 seconds or so.

So please humour me and give it a test as I could make
a calibrated audioscope from it. Reply back on here...

ENSURE that the sound card is NOT in use by another
application.

Code: Select all
# Test code for record and playback.
# import sys
# import os
def main():
    global record
    record=""
    # Record from my laptop`s mic.
    # Note sample rate unknown at the moment, (8KHz?).
    # Shout into the mic` for test purposes.
    audio=file('/dev/audio', 'rb')
    record=audio.read(65536)
    audio.close()
    # Playback from the sound card.
    audio=file('/dev/audio', 'wb')
    audio.write(record)
    audio.close()
main()


TIA...

EDIT:

I forgot to add:-

If it doesn`t seem to work properly after "import"(ing) rerun
the code as "record.main()[RETURN/ENTER]" and all will be
well. I forgot that it can take a little time for the "pyc" bytecode to be generated on the VERY first attempt...
73...

Bazza, G0LCU...

Team AMIGA...
User avatar
Bazza
LXF regular
 
Posts: 1476
Joined: Sat Mar 21, 2009 11:16 am
Location: Loughborough

Postby ScannerDarkly » Sat Nov 06, 2010 1:18 am

Why are the import lines 2-3 commented out?
Linux since Ubuntu 6.06.
ScannerDarkly
 
Posts: 30
Joined: Sat Jul 17, 2010 9:53 pm
Location: Cardiff

Postby Bazza » Sat Nov 06, 2010 7:58 am

They are not needed, and........

I quirk of mine...

I always make sure that......

import os
import sys

......are ready for my usage to remind me and are commented
out for this reason. They are the first two lines of a standard
page that I use when coding.

In this case I will be using this idea to get "real time" data
from audio input for an audio oscilloscope, (playing back is
unimportant to me ATM).

How I display this on screen using text mode will be uploaded
too when I have worked out the method.

IF those two imports are required for these two events then
they are there so that I don`t forget.

They are probably the two most important imports that I use.
73...

Bazza, G0LCU...

Team AMIGA...
User avatar
Bazza
LXF regular
 
Posts: 1476
Joined: Sat Mar 21, 2009 11:16 am
Location: Loughborough


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests