|
|
|
@ -178,7 +178,7 @@ class Recorder:
|
|
|
|
|
# CHECK AUX.mp3
|
|
|
|
|
self.mFileInfoDict = {}
|
|
|
|
|
self.mFileNameList=[]
|
|
|
|
|
self.mRecordedFramesList=[]
|
|
|
|
|
#self.mRecordedFramesList=[]
|
|
|
|
|
self.mStatusStr = "1_RECORDING"
|
|
|
|
|
if inChunkSecFloat != None: self.mFileAvailableChunkInt = 0
|
|
|
|
|
self.mDurationSecFloat = inDurationSecFloat
|
|
|
|
@ -250,7 +250,7 @@ class Recorder:
|
|
|
|
|
lCallbackThread.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def CaptureChunk(self, inExtra=None, inForceChunkBool=True):
|
|
|
|
|
def CaptureChunk(self, inExtra=None, inForceChunkBool=True, inShiftSecFloat = 0.0):
|
|
|
|
|
"""L-,W+: Зафиксировать захват аудио в виде промежуточного файла вида: <имя файла>_00000.mp3
|
|
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
@ -263,6 +263,8 @@ class Recorder:
|
|
|
|
|
:type inExtra: any, опционально
|
|
|
|
|
:param inForceChunkBool: True - вне зависимости от текущего режима перейти на режим сохранения по частям, по умолчанию True
|
|
|
|
|
:type inForceChunkBool: bool, опционально
|
|
|
|
|
:param inShiftSecFloat: Последние секунды, которые не записывать в промежуточный аудиофайл. Они будут началом следующего аудио отрывка, по умолчанию 0.0
|
|
|
|
|
:type inShiftSecFloat: float
|
|
|
|
|
:return: Наименование сохраненного аудиофайла
|
|
|
|
|
:rtype: str
|
|
|
|
|
"""
|
|
|
|
@ -273,10 +275,21 @@ class Recorder:
|
|
|
|
|
self.mFileAvailableChunkInt = self.mFileAvailableChunkInt + 1
|
|
|
|
|
lFileNameWExtStr = f"{lFileNameStr}.{self.mFileFormatStr}"
|
|
|
|
|
lFilePathStr = os.path.abspath(os.path.join(self.mFolderPathStr,lFileNameWExtStr))
|
|
|
|
|
lDataFrameBytes = b''.join(self.mRecordedFramesList)
|
|
|
|
|
if inShiftSecFloat != 0.0:
|
|
|
|
|
lFrameLenInt = int(self.mSampleSizeInt*inShiftSecFloat*self.mChannelCountInt*self.mSampleRateInt)
|
|
|
|
|
lFrameLenInt = int(lFrameLenInt // (self.mChannelCountInt * self.mSampleSizeInt)) * (self.mChannelCountInt * self.mSampleSizeInt)
|
|
|
|
|
if lFrameLenInt<len(lDataFrameBytes):
|
|
|
|
|
self.mRecordedFramesList=[lDataFrameBytes[-lFrameLenInt:]]
|
|
|
|
|
lDataFrameBytes = lDataFrameBytes[:-lFrameLenInt]
|
|
|
|
|
else:
|
|
|
|
|
lDataFrameBytes=b""
|
|
|
|
|
else:
|
|
|
|
|
self.mRecordedFramesList = []
|
|
|
|
|
# Advanced usage, if you have raw audio data:
|
|
|
|
|
sound = AudioSegment(
|
|
|
|
|
# raw audio data (bytes)
|
|
|
|
|
data=b''.join(self.mRecordedFramesList),
|
|
|
|
|
data=lDataFrameBytes,
|
|
|
|
|
# 2 byte (16 bit) samples
|
|
|
|
|
sample_width=self.mSampleSizeInt,
|
|
|
|
|
# 44.1 kHz frame rate
|
|
|
|
@ -284,9 +297,8 @@ class Recorder:
|
|
|
|
|
# stereo
|
|
|
|
|
channels=self.mChannelCountInt
|
|
|
|
|
)
|
|
|
|
|
self.mRecordedFramesList = []
|
|
|
|
|
lTimeSecFloat = time.time()
|
|
|
|
|
if not os.path.exists(os.path.abspath(self.mFolderPathStr)):
|
|
|
|
|
lTimeSecFloat = time.time() - inShiftSecFloat
|
|
|
|
|
if not os.path.exists(os.path.abspath(self.mFolderPathStr)):
|
|
|
|
|
os.mkdir(self.mFolderPathStr)
|
|
|
|
|
sound.export(lFilePathStr, format=f"{self.mFileFormatStr}")
|
|
|
|
|
self.mFileNameList.append(lFileNameWExtStr)
|
|
|
|
|