Example #1
0
    def set_volume_output(self, index, value, channels=1):

        if channels == 1:
            volume = pulsectl.PulseVolumeInfo([value])
        else:
            volume = pulsectl.PulseVolumeInfo([value,value])

        self.__pulse.sink_volume_set(index, volume)
Example #2
0
 def on_edit_clicked(self, widget):
     global currently_selected_map
     global pulse
     rule_name = currently_selected_map + ":" + self.restoration_name
     dialog = DialogEditRule(self, rule_name, self.restoration_row)
     response = dialog.run()
     if response == Gtk.ResponseType.OK:
         new_volume = float(dialog.volume_entry.get_text()) / 100.0
         if dialog.device_entry.get_text() != 'None':
             self.restoration_row.device = dialog.device_entry.get_text()
         if self.restoration_row.channel_count == 0 and new_volume > 0.0:
             # default to 2 channels
             self.restoration_row.channel_count = 2
             self.restoration_row.channel_list = [
                 'front-left', 'front-right'
             ]
             self.restoration_row.volume = pulsectl.PulseVolumeInfo(
                 struct_or_values=[0.50, 0.50], channels=2)
         if new_volume > 0:
             for i in range(len(self.restoration_row.volume.values)):
                 self.restoration_row.volume.values[i] = new_volume
         self.restoration_row.mute = 1 if dialog.mute_switch.get_state(
         ) else 0
         pulse.stream_restore_write(self.restoration_row, mode='replace')
         self.emit("refresh")
     dialog.destroy()
Example #3
0
 def setChannels(self, channels):
     try:
         volume_buffer = pulsectl.PulseVolumeInfo(
             [channel / 100. for channel in channels])
         self.pulse.volume_set(self.sink, volume_buffer)
     except pulsectl.PulseError as e:
         raise VolumeError(e)
Example #4
0
def read_mic(mic):
    sink = get_sink()
    orig_volume = sink.volume.values.copy()
    muting = False
    last_significant_input = 0
    last_tick = 0
    with mic.recorder(samplerate=sample_rate, channels=[-1]) as rec:
        while True:
            data = rec.record(numframes=sample_rate / 20)
            now = time.time()

            # pass data through:
            if muting or not now - last_significant_output < 2:
                sys.stdout.buffer.write(
                    (data * 2**16).astype(numpy.int16).tobytes())

            # notice loud input (e.g. claps):
            for v in data:
                if abs(v) > activate_if_mic_louder_than:
                    last_significant_input = now
                    break

            # notice continued speech:
            if last_significant_input != now and now - last_significant_input < 2:
                for v in data:
                    if abs(v) > extend_active_if_mic_louder_than:
                        last_significant_input = now
                        break

            # track current volume so we know it when we have to unmute:
            if not muting and now - last_tick > 5:
                orig_volume = get_sink().volume.values.copy()
                last_tick = now
                # We don't want to have to query the volume at the moment we mute,
                # because querying can take some time and we want muting to be immediate.
                # We don't use 'sink' here because it does not track volume changes.

            if muting and now - last_significant_input > 2:
                # unmute:
                pulse.volume_set(sink, pulsectl.PulseVolumeInfo(orig_volume))
                muting = False
            elif not muting and now - last_significant_input < 2:
                # mute:
                new_volume = pulsectl.PulseVolumeInfo(
                    output_volume_when_active, len(orig_volume))
                pulse.volume_set(sink, new_volume)
                muting = True
Example #5
0
    def set_source_volume(self, request, name):
        """
        Set source volume.

        **Example request**:

        .. sourcecode:: http

           PUT /api/v1/audio/sources/alsa_input.usb-Performance_Designed_Products_PDP_Audio_Device-00.analog-mono/volume

           [1.0]

        **Example response**:

        .. sourcecode:: http

           HTTP/1.1 200 OK
           Content-Type: application/json

           [1.0]
        """
        cors.config_cors(request)
        request.setHeader('Content-Type', 'application/json')

        body = json.loads(request.content.read())

        with pulsectl.Pulse('paradrop-daemon') as pulse:
            found = False
            for source in pulse.source_list():
                if source.name == name:
                    found = True
                    break

            if found:
                volume = pulsectl.PulseVolumeInfo(body)
                pulse.volume_set(source, volume)
                return json.dumps(body)
            else:
                request.setResponseCode(404)
                return '{}'
 def setVolume(self, o, volume):
     vol = volume / 100
     # TODO assumes two channels
     v = pulsectl.PulseVolumeInfo([vol, vol])
     pulse.volume_set(o, v)