6
# Check that the device can capture audio
7
if sf.SoundRecorder.CanCapture() == False:
8
print "Sorry, audio capture is not supported by your system"
11
# Choose the sample rate
13
SampleRate = int(raw_input("Please choose the sample rate for sound capture (44100 is CD quality) : "))
15
# Wait for user input...
16
print "Press enter to start recording audio"
19
# Here we'll use an integrated custom recorder, which saves the captured data into a sfSoundBuffer
20
Recorder = sf.SoundBufferRecorder()
22
# Audio capture is done in a separate thread, so we can block the main thread while it is capturing
23
Recorder.Start(SampleRate)
24
print "Recording... press enter to stop"
28
# Get the buffer containing the captured data
29
Buffer = Recorder.GetBuffer()
31
# Display captured sound informations
32
print "Sound information :"
33
print " " + str(Buffer.GetDuration()) + " seconds"
34
print " " + str(Buffer.GetSampleRate()) + " samples / seconds"
35
print " " + str(Buffer.GetChannelsCount()) + " channels"
37
# Choose what to do with the recorded sound data
38
Choice = str(raw_input("What do you want to do with captured sound (p = play, s = save) ? "))
42
Filename = str(raw_input("Choose the file to create : "))
45
Buffer.SaveToFile(Filename);
47
# Create a sound instance and play it
48
Sound = sf.Sound(Buffer)
52
while Sound.GetStatus() == sf.Sound.Playing:
53
# Display the playing position - I don't know how to do this in python
54
# std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec";
56
# Leave some CPU time for other threads
62
# Wait until the user presses 'enter' key
63
print "Press enter to exit..."