def playback(*args, **kargs): """A helper function to execute the playback_cmd. @param args: args passed to playback_cmd. @param kargs: kargs passed to playback_cmd. """ cmd_utils.execute(playback_cmd(*args, **kargs))
def capture(*args, **kargs): """A helper function to execute the capture_cmd. @param args: args passed to capture_cmd. @param kargs: kargs passed to capture_cmd. """ cmd_utils.execute(capture_cmd(*args, **kargs))
def loopback(*args, **kargs): """A helper function to execute loopback_cmd. @param args: args passed to loopback_cmd. @param kargs: kargs passed to loopback_cmd. """ cmd_utils.execute(loopback_cmd(*args, **kargs))
def dump_audio_diagnostics(file_path=None): """Dumps audio diagnostics results to a file Dumps the result of audio_diagnostics to a file. Returns a string containing the result if the file_path is not specified. @returns: None if 'file_path' is specified, otherwise, a string containing the audio diagnostic results. """ if file_path: with open(file_path, 'w') as f: return cmd_utils.execute([_AUDIO_DIAGNOSTICS_PATH], stdout=f) return cmd_utils.execute([_AUDIO_DIAGNOSTICS_PATH], stdout=subprocess.PIPE)
def get_audio_diagnostics(): """Gets audio diagnostic results. @returns: a string containing diagnostic results. """ return cmd_utils.execute([_AUDIO_DIAGNOSTICS_PATH], stdout=subprocess.PIPE)
def convert_raw_file(path_src, channels_src, bits_src, rate_src, path_dst): """Converts a raw file to a new format. @param path_src: The path to the source file. @param channels_src: The channel number of the source file. @param bits_src: The size of sample in bits of the source file. @param rate_src: The sampling rate of the source file. @param path_dst: The path to the destination file. The file name determines the new file format. """ sox_cmd = [SOX_PATH] sox_cmd += _raw_format_args(channels_src, bits_src, rate_src) sox_cmd += [path_src] sox_cmd += [path_dst] cmd_utils.execute(sox_cmd)
def convert_format(path_src, channels_src, bits_src, rate_src, path_dst, channels_dst, bits_dst, rate_dst, volume_scale, use_src_header=False, use_dst_header=False): """Converts a raw file to a new format. @param path_src: The path to the source file. @param channels_src: The channel number of the source file. @param bits_src: The size of sample in bits of the source file. @param rate_src: The sampling rate of the source file. @param path_dst: The path to the destination file. @param channels_dst: The channel number of the destination file. @param bits_dst: The size of sample in bits of the destination file. @param rate_dst: The sampling rate of the destination file. @param volume_scale: A float for volume scale used in sox command. E.g. 1.0 is the same. 0.5 to scale volume by half. -1.0 to invert the data. @param use_src_header: True to use header from source file and skip specifying channel, sample format, and rate for source. False otherwise. @param use_dst_header: True to use header for dst file. False to treat dst file as a raw file. """ sox_cmd = [SOX_PATH] if not use_src_header: sox_cmd += _raw_format_args(channels_src, bits_src, rate_src) sox_cmd += ['-v', '%f' % volume_scale] sox_cmd += [path_src] if not use_dst_header: sox_cmd += _raw_format_args(channels_dst, bits_dst, rate_dst) else: sox_cmd += _format_args(channels_dst, bits_dst, rate_dst) sox_cmd += [path_dst] cmd_utils.execute(sox_cmd)
def lowpass_filter(path_src, channels_src, bits_src, rate_src, path_dst, frequency): """Passes a raw file to a lowpass filter. @param path_src: The path to the source file. @param channels_src: The channel number of the source file. @param bits_src: The size of sample in bits of the source file. @param rate_src: The sampling rate of the source file. @param path_dst: The path to the destination file. @param frequency: A float for frequency used in sox command. The 3dB frequency of the lowpass filter. Checks manual of sox command for detail. """ sox_cmd = [SOX_PATH] sox_cmd += _raw_format_args(channels_src, bits_src, rate_src) sox_cmd += [path_src] sox_cmd += _raw_format_args(channels_src, bits_src, rate_src) sox_cmd += [path_dst] sox_cmd += ['lowpass', '-2', str(frequency)] cmd_utils.execute(sox_cmd)
def convert_format(path_src, channels_src, bits_src, rate_src, path_dst, channels_dst, bits_dst, rate_dst, volume_scale): """Converts a raw file to a new format. @param path_src: The path to the source file. @param channels_src: The channel number of the source file. @param bits_src: The size of sample in bits of the source file. @param rate_src: The sampling rate of the source file. @param path_dst: The path to the destination file. @param channels_dst: The channel number of the destination file. @param bits_dst: The size of sample in bits of the destination file. @param rate_dst: The sampling rate of the destination file. @param volume_scale: A float for volume scale used in sox command. E.g. 1.0 is the same. 0.5 to scale volume by half. -1.0 to invert the data. """ sox_cmd = [SOX_PATH] sox_cmd += _raw_format_args(channels_src, bits_src, rate_src) sox_cmd += ['-v', '%f' % volume_scale] sox_cmd += [path_src] sox_cmd += _raw_format_args(channels_dst, bits_dst, rate_dst) sox_cmd += [path_dst] cmd_utils.execute(sox_cmd)
def get_num_seq_clients(): '''Returns the number of seq clients. The number of clients is parsed from aconnect -io. This is run as the chronos user to catch permissions problems. Sample content: client 0: 'System' [type=kernel] 0 'Timer ' 1 'Announce ' client 14: 'Midi Through' [type=kernel] 0 'Midi Through Port-0' @raise RuntimeError: If no seq device is available. ''' cmd = [ACONNECT_PATH, '-io'] output = cmd_utils.execute(cmd, stdout=subprocess.PIPE, run_as='chronos') num_clients = 0 for line in output.splitlines(): match = CLIENT_NUM_RE.match(line) if match: num_clients += 1 return num_clients
def record(*args, **kwargs): '''A helper function to execute record_cmd. @param kwargs: kwargs passed to record_cmd. ''' cmd_utils.execute(record_cmd(*args, **kwargs))
def playback(*args, **kwargs): '''A helper funciton to execute playback_cmd. @param kwargs: kwargs passed to playback_cmd. ''' cmd_utils.execute(playback_cmd(*args, **kwargs))
def noise_reduce(*args, **kargs): """A helper function to execute the noise_reduce_cmd.""" return cmd_utils.execute(noise_reduce_cmd(*args, **kargs))
def noise_profile(*arg, **karg): """A helper function to execute the noise_profile_cmd.""" return cmd_utils.execute(noise_profile_cmd(*arg, **karg))