コード例 #1
0
ファイル: pulse.py プロジェクト: mjem/carrie
def get_volume(target="Sink #0"):
	#         Volume: 0:  60% 1:  16%

	trigger = False
	matcher = re.compile(r'.*Volume: (?P<vals>.*)')
	for line in shell('pactl', 'list'):
		# print 'LINE ', line
		if trigger:
			# print line
			match = matcher.match(line)
			if match is not None:
				# print 'MATCH ', match.group('vals'), 'x', match.group('vals').split(), 'x'
				#res = {}
				acc = 0.0
				cc = 0
				for k, v in paste(match.group('vals').split()):
					# assume the value is like "40%"
					# res[k] = int(v.replace('%', '')) / 100
					acc += int(v.replace('%', '')) / 100
					cc += 1

				res = acc / cc
				logging.debug('Read volume as {vol}'.format(vol=res))
				return res

		if line.startswith(target):
			# print 'TRIGGER ', line
			trigger = True

	return None
コード例 #2
0
def get_volume(target="Sink #0"):
    #         Volume: 0:  60% 1:  16%

    trigger = False
    matcher = re.compile(r'.*Volume: (?P<vals>.*)')
    for line in shell('pactl', 'list'):
        # print 'LINE ', line
        if trigger:
            # print line
            match = matcher.match(line)
            if match is not None:
                # print 'MATCH ', match.group('vals'), 'x', match.group('vals').split(), 'x'
                #res = {}
                acc = 0.0
                cc = 0
                for k, v in paste(match.group('vals').split()):
                    # assume the value is like "40%"
                    # res[k] = int(v.replace('%', '')) / 100
                    acc += int(v.replace('%', '')) / 100
                    cc += 1

                res = acc / cc
                logging.debug('Read volume as {vol}'.format(vol=res))
                return res

        if line.startswith(target):
            # print 'TRIGGER ', line
            trigger = True

    return None
コード例 #3
0
ファイル: pulse.py プロジェクト: mjem/carrie
def set_volume(val, sink=0):
	logging.debug('Setting volume to {vol}'.format(vol=val))
	shell('pactl', 'set-sink-volume', str(sink), str(int(val*65535)))
コード例 #4
0
def set_volume(val, sink=0):
    logging.debug('Setting volume to {vol}'.format(vol=val))
    shell('pactl', 'set-sink-volume', str(sink), str(int(val * 65535)))