मेरा मानना है कि WAVE मॉड्यूल रिकॉर्डिंग का समर्थन नहीं करता है, बस मौजूदा फ़ाइलों को संसाधित करता है। आप वास्तव में रिकॉर्डिंग के लिए PyAudio को देखना चाहते हैं । WAV दुनिया के सबसे सरल फ़ाइल प्रारूप के बारे में है। PaInt16 में आपको केवल एक स्तर पर प्रतिनिधित्व करने वाला एक हस्ताक्षरित पूर्णांक मिलता है, और 0 के करीब है। मुझे याद नहीं है कि WAV फाइलें पहले उच्च या निम्न बाइट हैं, लेकिन कुछ इस तरह से काम करना चाहिए (क्षमा करें, मैं वास्तव में अजगर प्रोग्रामर नहीं हूं:
from array import array
# you'll probably want to experiment on threshold
# depends how noisy the signal
threshold = 10
max_value = 0
as_ints = array('h', data)
max_value = max(as_ints)
if max_value > threshold:
# not silence
संदर्भ के लिए रखी गई रिकॉर्डिंग के लिए PyAudio कोड:
import pyaudio
import sys
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
output=True,
frames_per_buffer=chunk)
print "* recording"
for i in range(0, 44100 / chunk * RECORD_SECONDS):
data = stream.read(chunk)
# check for silence here by comparing the level with 0 (or some threshold) for
# the contents of data.
# then write data or not to a file
print "* done"
stream.stop_stream()
stream.close()
p.terminate()