Welcome, guest | Sign In | My Account | Store | Cart

This very simple DEMO code records a few seconds of your voice from a microphone, (internal mic' on a laptop), and replays your voice immedaiately after recording. It goes without saying that the RAW recording can be saved in any extension of your choice and used as error reporting using the playback method.

There is the possibility of using it as a simple means of a single channel audio oscilloscope using the external mic input and suitable Python GUI or with simple home built HW a seismometer recorder, plus other ideas.

Enjoy finding simple solutions to often very difficult problems...

Read the code for more information...

73...

Bazza, G0LCU...

Team AMIGA...

Python, 46 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# DEMO code for recording a few seconds of sound and playing back the same
# from inside a terminal running standard Python 2.x in a Linux distro...
# (I think this is Python 3.x compatible too.)
#
# This assumes /dev/audio exists, if NOT, then install oss-compat
# from your distro`s repository.
#
# (Original idea copyright, (C)2010, B.Walker, G0LCU.)
# Now issued as Public Domain, (to LXF).
#
# You may do as you like with this idea but some acknowledgement
# would be appreciated.
#
# Save in the Python/Lib drawer(/folder/directory) as arp.py.
#
# Use "import arp<RETURN/ENTER>" without the quotes to test it.
#
# Once imported start talking loudly into a laptop`s internal microphone
# for about 6 seconds then wait for the recorded sound to be played back.
#
# Tested on PCLinuxOS 2009, Knoppix 5.1.1, (and Debian 6.0.0 <- WITH
# oss-compat installed).
#
# Ensure the sound system is not already in use.
#
# These two imports NOT needed for this quick demo.
# import sys
# import os

def main():
    global record
    record=""
    # Record from my Laptop`s, Notebook`s and Netbook`s mic.
    # Note sample rate unknown at the moment, (8KHz?).
    # Shout into the internal mic` for test purposes.
    audio=file('/dev/audio', 'rb')
    record=audio.read(65536)
    audio.close()
    # Playback from the sound card(s).
    audio=file('/dev/audio', 'wb')
    audio.write(record)
    audio.close()
main()

# End of record/playback DEMO.
# Enjoy finding simple solutions to often very difficult problems.
Created by Barry Walker on Fri, 25 Feb 2011 (MIT)
Python recipes (4591)
Barry Walker's recipes (73)

Required Modules

  • (none specified)

Other Information and Tasks