def run_once(self): """Entry point of this test.""" self.chrome.browser.platform.SetHTTPServerDirectories(self.bindir) video_url = self.chrome.browser.platform.http_server.UrlOf( os.path.join(self.bindir, 'youtube.html')) logging.info('Playing back youtube media file %s.', video_url) noise_file = os.path.join(self.resultsdir, "noise.wav") recorded_file = os.path.join(self.resultsdir, "recorded.wav") loopback_file = os.path.join(self.resultsdir, "loopback.wav") # Record a sample of "silence" to use as a noise profile. cras_utils.capture(noise_file, duration=3) # Play a video and record the audio output self.play_video(self.chrome.browser.tabs[0], video_url) p1 = cmd_utils.popen( cras_utils.capture_cmd(recorded_file, duration=TEST_DURATION)) p2 = cmd_utils.popen( cras_utils.loopback_cmd(loopback_file, duration=TEST_DURATION)) cmd_utils.wait_and_check_returncode(p1, p2) # See if we recorded something loopback_stats = [ audio_helper.get_channel_sox_stat(loopback_file, i) for i in (1, 2) ] logging.info('loopback stats: %s', [str(s) for s in loopback_stats]) rms_value = audio_helper.reduce_noise_and_get_rms( recorded_file, noise_file)[0] self.write_perf_keyval({'rms_value': rms_value})
def rms_test(self, tab, media_file, noiseprof_file, test_duration): logging.info('rms test on media file %s.', media_file) recorded_file = os.path.join(self.resultsdir, 'recorded.wav') loopback_file = os.path.join(self.resultsdir, 'loopback.wav') # Plays the media_file in the browser. self.play_media(tab, media_file) # Record the audio output and also the CRAS loopback output. p1 = cmd_utils.popen( cras_utils.capture_cmd(recorded_file, duration=test_duration)) p2 = cmd_utils.popen( cras_utils.loopback_cmd(loopback_file, duration=test_duration)) cmd_utils.wait_and_check_returncode(p1, p2) # See if we recorded something. # We captured two channels of audio in the CRAS loopback. # The RMS values are for debugging only. loopback_stats = [ audio_helper.get_channel_sox_stat(loopback_file, i) for i in (1, 2) ] logging.info('loopback stats: %s', [str(s) for s in loopback_stats]) reduced_file = tempfile.NamedTemporaryFile() sox_utils.noise_reduce(recorded_file, reduced_file.name, noiseprof_file) rms = audio_helper.get_rms(reduced_file.name)[0] self._rms_values['%s_rms_value' % media_file.replace('.', '_')] = rms # Make sure the audio can be played to the end. self.wait_player_end(tab)
def start(self, data_format): """Starts recording. Starts recording subprocess. It can be stopped by calling stop(). @param data_format: A dict containing: file_type: 'raw'. sample_format: 'S16_LE' for 16-bit signed integer in little-endian. channel: channel number. rate: sampling rate. @raises: RecorderError: If recording subprocess is terminated unexpectedly. """ self._capture_subprocess = cmd_utils.popen( cras_utils.capture_cmd(capture_file=self.file_path, duration=None, channels=data_format['channel'], rate=data_format['rate']))