Beispiel #1
0
    def __init__(self, default_device_name):
        super().__init__()
        self.default_device_name = default_device_name
        self._pull_timer = QTimer()
        self._pull_timer.setInterval(3000)
        self._pull_timer.timeout.connect(self.write_to_buffer)

        self._audio_input = None
        self._input = None
        self._audio_data_handler = None

        devices = QAudioDeviceInfo.availableDevices(QAudio.AudioInput)
        self._device = None
        self.monitors = []

        for item in devices:
            dev_name = item.deviceName()
            if dev_name.endswith(".monitor"):
                self.monitors.append(item)
            if self.default_device_name and self.default_device_name == item.deviceName(
            ):
                self._device = item
        if not self._device:
            try:
                self._device = self.monitors[0]
            except IndexError:
                self._device = QAudioDeviceInfo.defaultInputDevice()

        self.initialize_audio()

        self.start_audio()
Beispiel #2
0
    def __init__(self, args=None):
        AudioDriver.__init__(self, args)
        if args and args.audio_device:
            available_devices = {}
            for device in QAudioDeviceInfo.availableDevices(
                    QAudio.AudioOutput):
                available_devices[device.deviceName()] = device
            try:
                device = available_devices[args.audio_device]
            except KeyError:
                logger.error("Unknown audio device: %r", args.audio_device)
                logger.info("Available devices:")
                for device_name in available_devices:
                    logger.info("    %r", device_name)
                raise AudioDriverError("Unsupported audio device")
        else:
            device = QAudioDeviceInfo.defaultOutputDevice()

        playback_format = device.preferredFormat()
        self.decoder = QAudioDecoder()
        self.decoder.setAudioFormat(playback_format)
        self.output = QAudioOutput(device, playback_format)

        self.device_name = device.deviceName()
        self.duration = None
        self.bytes_written = 0
        self.last_frame = b""
        self.starting = False
        self.output_dev = None
        self.current_file = None
        self.current_buffer = None
        self.current_buffer_pos = 0

        self.output.stateChanged.connect(self.output_state_changed)
        self.output.notify.connect(self.tick)

        self.decoder.error.connect(self.decoder_error)
        self.decoder.finished.connect(self.decoder_finished)
        self.decoder.stateChanged.connect(self.decoder_state_changed)
        self.decoder.positionChanged.connect(self.decoder_pos_changed)
        self.decoder.bufferReady.connect(self.buffer_ready)
Beispiel #3
0
    def initializeWindow(self):
        layout = QVBoxLayout()

        self.m_deviceBox = QComboBox()
        self.m_deviceBox.activated[int].connect(self.deviceChanged)
        for deviceInfo in QAudioDeviceInfo.availableDevices(
                QAudio.AudioOutput):
            self.m_deviceBox.addItem(deviceInfo.deviceName(), deviceInfo)

        layout.addWidget(self.m_deviceBox)

        self.m_modeButton = QPushButton()
        self.m_modeButton.clicked.connect(self.toggleMode)
        self.m_modeButton.setText(self.PUSH_MODE_LABEL)

        layout.addWidget(self.m_modeButton)

        self.m_suspendResumeButton = QPushButton(
            clicked=self.toggleSuspendResume)
        self.m_suspendResumeButton.setText(self.SUSPEND_LABEL)

        layout.addWidget(self.m_suspendResumeButton)

        volumeBox = QHBoxLayout()
        volumeLabel = QLabel("Volume:")
        self.m_volumeSlider = QSlider(Qt.Horizontal,
                                      minimum=0,
                                      maximum=100,
                                      singleStep=10)
        self.m_volumeSlider.valueChanged.connect(self.volumeChanged)

        volumeBox.addWidget(volumeLabel)
        volumeBox.addWidget(self.m_volumeSlider)

        layout.addLayout(volumeBox)

        window = QWidget()
        window.setLayout(layout)

        self.setCentralWidget(window)
Beispiel #4
0
    def initializeWindow(self):
        layout = QVBoxLayout()

        self.m_deviceBox = QComboBox()
        self.m_deviceBox.activated[int].connect(self.deviceChanged)
        for deviceInfo in QAudioDeviceInfo.availableDevices(QAudio.AudioOutput):
            self.m_deviceBox.addItem(deviceInfo.deviceName(), deviceInfo)

        layout.addWidget(self.m_deviceBox)

        self.m_modeButton = QPushButton()
        self.m_modeButton.clicked.connect(self.toggleMode)
        self.m_modeButton.setText(self.PUSH_MODE_LABEL)

        layout.addWidget(self.m_modeButton)

        self.m_suspendResumeButton = QPushButton(
                clicked=self.toggleSuspendResume)
        self.m_suspendResumeButton.setText(self.SUSPEND_LABEL)

        layout.addWidget(self.m_suspendResumeButton)

        volumeBox = QHBoxLayout()
        volumeLabel = QLabel("Volume:")
        self.m_volumeSlider = QSlider(Qt.Horizontal, minimum=0, maximum=100,
                singleStep=10)
        self.m_volumeSlider.valueChanged.connect(self.volumeChanged)

        volumeBox.addWidget(volumeLabel)
        volumeBox.addWidget(self.m_volumeSlider)

        layout.addLayout(volumeBox)

        window = QWidget()
        window.setLayout(layout)

        self.setCentralWidget(window)
Beispiel #5
0
 def interfaces(self):
     self.devices = QAudioDeviceInfo.availableDevices(QAudio.AudioInput)
     self.default = QAudioDeviceInfo.defaultInputDevice()
     print(self.default.supportedCodecs())