def _validate_impl(self, audio_file=None):
        """Validate playback (interface override).

        @param audio_file: Name of audio file on the test host to validate
                           against.
        """
        req = sequenced_request.SequencedFeedbackRequest(
            self.test, self.dut, None)
        msg = 'Playback finished on %(dut)s.'
        if audio_file is None:
            req.append_question(msg,
                                input_handlers.YesNoInputHandler(default=True),
                                prompt='Did you hear audible sound?')
            err_msg = 'User did not hear audible feedback'
        else:
            if not self._playback_wav_file(msg, audio_file):
                return (tester_feedback_client.QUERY_RET_ERROR,
                        'Failed to playback recorded audio')
            req.append_question(
                None,
                input_handlers.YesNoInputHandler(default=True),
                prompt=('Was the audio produced identical to the refernce '
                        'audio file?'))
            err_msg = ('Audio produced was not identical to the reference '
                       'audio file')

        if not self._process_request(req):
            return (tester_feedback_client.QUERY_RET_FAIL, err_msg)
    def _validate_impl(self,
                       captured_audio_file,
                       sample_width,
                       sample_rate=None,
                       num_channels=None,
                       peak_percent_min=1,
                       peak_percent_max=100):
        """Validate recording (interface override).

        @param captured_audio_file: Path to the recorded WAV file.
        @param sample_width: The recorded sample width.
        @param sample_rate: The recorded sample rate.
        @param num_channels: The number of recorded channels.
        @peak_percent_min: Lower bound on peak recorded volume as percentage of
                           max molume (0-100). Default is 1%.
        @peak_percent_max: Upper bound on peak recorded volume as percentage of
                           max molume (0-100). Default is 100% (no limit).
        """
        # Check the WAV file properties first.
        try:
            site_utils.check_wav_file(captured_audio_file,
                                      num_channels=num_channels,
                                      sample_rate=sample_rate,
                                      sample_width=sample_width)
        except ValueError as e:
            return (tester_feedback_client.QUERY_RET_FAIL,
                    'Recorded audio file is invalid: %s' % e)

        # Verify playback of the recorded audio.
        props = ['has sample width of %d' % sample_width]
        if sample_rate is not None:
            props.append('has sample rate of %d' % sample_rate)
        if num_channels is not None:
            props.append('has %d recorded channels' % num_channels)
        props_str = '%s%s%s' % (', '.join(
            props[:-1]), ', and ' if len(props) > 1 else '', props[-1])

        msg = 'Recording finished on %%(dut)s. It %s.' % props_str
        if not self._playback_wav_file(msg, captured_audio_file):
            return (tester_feedback_client.QUERY_RET_ERROR,
                    'Failed to playback recorded audio')

        req = sequenced_request.SequencedFeedbackRequest(
            self.test, self.dut, None)
        req.append_question(
            None,
            input_handlers.YesNoInputHandler(default=True),
            prompt='Did the recording capture the sound produced?')
        if not self._process_request(req):
            return (
                tester_feedback_client.QUERY_RET_FAIL,
                'Recorded audio is not identical to what the user produced')
    def _validate_impl(self, audio_file=None):
        """Validate silence (interface override).

        @param audio_file: Name of audio file on the test host to validate
                           against.
        """
        if audio_file is not None:
            return (
                tester_feedback_client.QUERY_RET_ERROR,
                'Not expecting an audio file entry when validating silence')
        req = sequenced_request.SequencedFeedbackRequest(
            self.test, self.dut, None)
        req.append_question('Silence playback finished on %(dut)s.',
                            input_handlers.YesNoInputHandler(default=True),
                            prompt='Did you hear silence?')
        if not self._process_request(req):
            return (tester_feedback_client.QUERY_RET_FAIL,
                    'User did not hear silence')
    def _validate_impl(self, captured_audio_file):
        """Validate recording (interface override).

        @param captured_audio_file: Path to the recorded WAV file.
        """
        # Check the WAV file properties first.
        try:
            audio_utils.check_wav_file(captured_audio_file,
                                       num_channels=self._num_channels,
                                       sample_rate=self._sample_rate,
                                       sample_width=self._sample_width)
        except ValueError as e:
            return (tester_feedback_client.QUERY_RET_FAIL,
                    'Recorded audio file is invalid: %s' % e)

        # Verify playback of the recorded audio.
        props = [
            'as sample width of %d' % self._sample_width,
            'has sample rate of %d' % self._sample_rate,
            'has %d recorded channels' % self._num_channels
        ]
        if self._frequency is not None:
            props.append('has frequency of %d Hz' % self._frequency)
        props_str = '%s%s%s' % (', '.join(
            props[:-1]), ', and ' if len(props) > 1 else '', props[-1])

        msg = 'Recording finished on %%(dut)s. It %s.' % props_str
        if not self._playback_wav_file(msg, captured_audio_file):
            return (tester_feedback_client.QUERY_RET_ERROR,
                    'Failed to playback recorded audio')

        req = sequenced_request.SequencedFeedbackRequest(
            self.test, self.dut, None)
        req.append_question(
            None,
            input_handlers.YesNoInputHandler(default=True),
            prompt='Did the recording capture the sound produced?')
        if not self._process_request(req):
            return (
                tester_feedback_client.QUERY_RET_FAIL,
                'Recorded audio is not identical to what the user produced')