| View previous topic :: View next topic |
| Author |
Message |
Bazza LXF regular

Joined: Sat Mar 21, 2009 11:16 am Posts: 1381 Location: Loughborough
|
Posted: Fri Oct 01, 2010 8:25 pm Post subject: As an addendum to my Python freebie code below... |
|
|
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 |
|
 |
ScannerDarkly
Joined: Sat Jul 17, 2010 10:53 pm Posts: 30 Location: Cardiff
|
Posted: Sat Nov 06, 2010 1:18 am Post subject: |
|
|
Why are the import lines 2-3 commented out? _________________ Linux since Ubuntu 6.06. |
|
| Back to top |
|
 |
Bazza LXF regular

Joined: Sat Mar 21, 2009 11:16 am Posts: 1381 Location: Loughborough
|
Posted: Sat Nov 06, 2010 7:58 am Post subject: |
|
|
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 previous topic :: View next topic |
|