def initialize_audio(self): """Set up parameters for audio recording.""" self._format = QAudioFormat() self._format.setSampleRate(44100) self._format.setChannelCount(1) self._format.setSampleSize(8) self._format.setSampleType(QAudioFormat.UnSignedInt) self._format.setByteOrder(QAudioFormat.LittleEndian) self._format.setCodec("audio/pcm") device_info = QAudioDeviceInfo(self._device) if not device_info.isFormatSupported(self._format): print("Default format not supported - trying to use nearest.") self._format = device_info.nearestFormat(self._format) self._audio_data_handler = AudioDataHandler(self._format) self._audio_input = QAudioInput(self._device, self._format) self._audio_data_handler.data_ready.connect(self.data_ready)
def initializeAudio(self): self.m_pullTimer = QTimer(self) self.m_pullTimer.timeout.connect(self.pullTimerExpired) self.m_pullMode = True self.m_format = QAudioFormat() self.m_format.setSampleRate(self.DataSampleRateHz) self.m_format.setChannelCount(1) self.m_format.setSampleSize(16) self.m_format.setCodec('audio/pcm') self.m_format.setByteOrder(QAudioFormat.LittleEndian) self.m_format.setSampleType(QAudioFormat.SignedInt) info = QAudioDeviceInfo(QAudioDeviceInfo.defaultOutputDevice()) if not info.isFormatSupported(self.m_format): qWarning("Default format not supported - trying to use nearest") self.m_format = info.nearestFormat(self.m_format) self.m_generator = Generator(self.m_format, self.DurationSeconds * 1000000, self.ToneSampleRateHz, self) self.createAudioOutput()