當前位置: 首頁>>代碼示例>>Python>>正文


Python audioop.getsample方法代碼示例

本文整理匯總了Python中audioop.getsample方法的典型用法代碼示例。如果您正苦於以下問題:Python audioop.getsample方法的具體用法?Python audioop.getsample怎麽用?Python audioop.getsample使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在audioop的用法示例。


在下文中一共展示了audioop.getsample方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_issue7673

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def test_issue7673(self):
        state = None
        for data, size in INVALID_DATA:
            size2 = size
            self.assertRaises(audioop.error, audioop.getsample, data, size, 0)
            self.assertRaises(audioop.error, audioop.max, data, size)
            self.assertRaises(audioop.error, audioop.minmax, data, size)
            self.assertRaises(audioop.error, audioop.avg, data, size)
            self.assertRaises(audioop.error, audioop.rms, data, size)
            self.assertRaises(audioop.error, audioop.avgpp, data, size)
            self.assertRaises(audioop.error, audioop.maxpp, data, size)
            self.assertRaises(audioop.error, audioop.cross, data, size)
            self.assertRaises(audioop.error, audioop.mul, data, size, 1.0)
            self.assertRaises(audioop.error, audioop.tomono, data, size, 0.5, 0.5)
            self.assertRaises(audioop.error, audioop.tostereo, data, size, 0.5, 0.5)
            self.assertRaises(audioop.error, audioop.add, data, data, size)
            self.assertRaises(audioop.error, audioop.bias, data, size, 0)
            self.assertRaises(audioop.error, audioop.reverse, data, size)
            self.assertRaises(audioop.error, audioop.lin2lin, data, size, size2)
            self.assertRaises(audioop.error, audioop.ratecv, data, size, 1, 1, 1, state)
            self.assertRaises(audioop.error, audioop.lin2ulaw, data, size)
            self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
            self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:test_audioop.py

示例2: test_string

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def test_string(self):
        data = 'abcd'
        size = 2
        self.assertRaises(TypeError, audioop.getsample, data, size, 0)
        self.assertRaises(TypeError, audioop.max, data, size)
        self.assertRaises(TypeError, audioop.minmax, data, size)
        self.assertRaises(TypeError, audioop.avg, data, size)
        self.assertRaises(TypeError, audioop.rms, data, size)
        self.assertRaises(TypeError, audioop.avgpp, data, size)
        self.assertRaises(TypeError, audioop.maxpp, data, size)
        self.assertRaises(TypeError, audioop.cross, data, size)
        self.assertRaises(TypeError, audioop.mul, data, size, 1.0)
        self.assertRaises(TypeError, audioop.tomono, data, size, 0.5, 0.5)
        self.assertRaises(TypeError, audioop.tostereo, data, size, 0.5, 0.5)
        self.assertRaises(TypeError, audioop.add, data, data, size)
        self.assertRaises(TypeError, audioop.bias, data, size, 0)
        self.assertRaises(TypeError, audioop.reverse, data, size)
        self.assertRaises(TypeError, audioop.lin2lin, data, size, size)
        self.assertRaises(TypeError, audioop.ratecv, data, size, 1, 1, 1, None)
        self.assertRaises(TypeError, audioop.lin2ulaw, data, size)
        self.assertRaises(TypeError, audioop.lin2alaw, data, size)
        self.assertRaises(TypeError, audioop.lin2adpcm, data, size, None) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:24,代碼來源:test_audioop.py

示例3: fadeout

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def fadeout(self, seconds: float, target_volume: float = 0.0) -> 'Sample':
        """Fade the end of the sample out to the target volume (usually zero) in the given time."""
        if self.__locked:
            raise RuntimeError("cannot modify a locked sample")
        if not self.__frames:
            return self
        seconds = min(seconds, self.duration)
        i = self.frame_idx(self.duration-seconds)
        begin = self.__frames[:i]
        end = self.__frames[i:]  # we fade this chunk
        numsamples = len(end)/self.__samplewidth
        decrease = 1.0-target_volume
        _sw = self.__samplewidth     # optimization
        _getsample = audioop.getsample   # optimization
        faded = Sample.get_array(_sw, [int(_getsample(end, _sw, i)*(1.0-i*decrease/numsamples)) for i in range(int(numsamples))])
        end = faded.tobytes()
        if sys.byteorder == "big":
            end = audioop.byteswap(end, self.__samplewidth)
        self.__frames = begin + end
        return self 
開發者ID:irmen,項目名稱:synthesizer,代碼行數:22,代碼來源:sample.py

示例4: fadein

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def fadein(self, seconds: float, start_volume: float = 0.0) -> 'Sample':
        """Fade the start of the sample in from the starting volume (usually zero) in the given time."""
        if self.__locked:
            raise RuntimeError("cannot modify a locked sample")
        if not self.__frames:
            return self
        seconds = min(seconds, self.duration)
        i = self.frame_idx(seconds)
        begin = self.__frames[:i]  # we fade this chunk
        end = self.__frames[i:]
        numsamples = len(begin)/self.__samplewidth
        increase = 1.0-start_volume
        _sw = self.__samplewidth     # optimization
        _getsample = audioop.getsample   # optimization
        _incr = increase/numsamples    # optimization
        faded = Sample.get_array(_sw, [int(_getsample(begin, _sw, i)*(i*_incr+start_volume)) for i in range(int(numsamples))])
        begin = faded.tobytes()
        if sys.byteorder == "big":
            begin = audioop.byteswap(begin, self.__samplewidth)
        self.__frames = begin + end
        return self 
開發者ID:irmen,項目名稱:synthesizer,代碼行數:23,代碼來源:sample.py

示例5: test_getsample

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def test_getsample(self):
        for w in 1, 2, 4:
            data = packs[w](0, 1, -1, maxvalues[w], minvalues[w])
            self.assertEqual(audioop.getsample(data, w, 0), 0)
            self.assertEqual(audioop.getsample(data, w, 1), 1)
            self.assertEqual(audioop.getsample(data, w, 2), -1)
            self.assertEqual(audioop.getsample(data, w, 3), maxvalues[w])
            self.assertEqual(audioop.getsample(data, w, 4), minvalues[w]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_audioop.py

示例6: test_getsample

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def test_getsample(self):
        for w in 1, 2, 3, 4:
            data = packs[w](0, 1, -1, maxvalues[w], minvalues[w])
            self.assertEqual(audioop.getsample(data, w, 0), 0)
            self.assertEqual(audioop.getsample(bytearray(data), w, 0), 0)
            self.assertEqual(audioop.getsample(memoryview(data), w, 0), 0)
            self.assertEqual(audioop.getsample(data, w, 1), 1)
            self.assertEqual(audioop.getsample(data, w, 2), -1)
            self.assertEqual(audioop.getsample(data, w, 3), maxvalues[w])
            self.assertEqual(audioop.getsample(data, w, 4), minvalues[w]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:12,代碼來源:test_audioop.py

示例7: gendata2

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def gendata2():
    if verbose:
        print 'getsample'
    if audioop.getsample('\0\1', 2, 0) == 1:
        return '\0\0\0\1\0\2'
    else:
        return '\0\0\1\0\2\0' 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:9,代碼來源:test_audioop.py

示例8: gendata4

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def gendata4():
    if verbose:
        print 'getsample'
    if audioop.getsample('\0\0\0\1', 4, 0) == 1:
        return '\0\0\0\0\0\0\0\1\0\0\0\2'
    else:
        return '\0\0\0\0\1\0\0\0\2\0\0\0' 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:9,代碼來源:test_audioop.py

示例9: testgetsample

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def testgetsample(data):
    if verbose:
        print 'getsample'
    for i in range(3):
        if audioop.getsample(data[0], 1, i) != i or \
                  audioop.getsample(data[1], 2, i) != i or \
                  audioop.getsample(data[2], 4, i) != i:
            return 0
    return 1 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:11,代碼來源:test_audioop.py

示例10: recordAudioSegments

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import getsample [as 別名]
def recordAudioSegments(RecordPath, BLOCKSIZE):	
	# This function is used for recording audio segments (until ctr+c is pressed)
	# ARGUMENTS:
	# - RecordPath:		the path where the wav segments will be stored
	# - BLOCKSIZE:		segment recording size (in seconds)
	# 
	# NOTE: filenames are based on clock() value
	
	print "Press Ctr+C to stop recording"
	RecordPath += os.sep
	d = os.path.dirname(RecordPath)
	if os.path.exists(d) and RecordPath!=".":
		shutil.rmtree(RecordPath)	
	os.makedirs(RecordPath)	

	inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NONBLOCK)
	inp.setchannels(1)
	inp.setrate(Fs)
	inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
	inp.setperiodsize(512)
	midTermBufferSize = int(Fs*BLOCKSIZE)
	midTermBuffer = []
	curWindow = []
	elapsedTime = "%08.3f" % (time.time())
	while 1:
			l,data = inp.read()		   
		    	if l:
				for i in range(len(data)/2):
					curWindow.append(audioop.getsample(data, 2, i))
		
				if (len(curWindow)+len(midTermBuffer)>midTermBufferSize):
					samplesToCopyToMidBuffer = midTermBufferSize - len(midTermBuffer)
				else:
					samplesToCopyToMidBuffer = len(curWindow)

				midTermBuffer = midTermBuffer + curWindow[0:samplesToCopyToMidBuffer];
				del(curWindow[0:samplesToCopyToMidBuffer])
			

			if len(midTermBuffer) == midTermBufferSize:
				# allData = allData + midTermBuffer				
				curWavFileName = RecordPath + os.sep + str(elapsedTime) + ".wav"				
				midTermBufferArray = numpy.int16(midTermBuffer)
				wavfile.write(curWavFileName, Fs, midTermBufferArray)
				print "AUDIO  OUTPUT: Saved " + curWavFileName
				midTermBuffer = []
				elapsedTime = "%08.3f" % (time.time()) 
開發者ID:tyiannak,項目名稱:pyAudioAnalysis,代碼行數:49,代碼來源:audioAnalysisRecordAlsa.py


注:本文中的audioop.getsample方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。