Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1462
Location: Loughborough

PostPosted: Fri Oct 01, 2010 8:25 pm    Post subject: As an addendum to my Python freebie code below... Reply with quote

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:
# 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...
Back to top
View user's profile Send private message
ScannerDarkly



Joined: Sat Jul 17, 2010 10:53 pm
Posts: 30
Location: Cardiff

PostPosted: Sat Nov 06, 2010 1:18 am    Post subject: Reply with quote

Why are the import lines 2-3 commented out?
_________________
Linux since Ubuntu 6.06.
Back to top
View user's profile Send private message
Bazza
LXF regular


Joined: Sat Mar 21, 2009 11:16 am
Posts: 1462
Location: Loughborough

PostPosted: Sat Nov 06, 2010 7:58 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast