<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def speak(self, text, espeak_opts='-a 200 -s 130', volume=100, play_type=PLAY_WAIT_FOR_COMPLETE):
 """ Speak the given text aloud. Uses the ``espeak`` external command. :param string text: The text to speak :param string espeak_opts: ``espeak`` command options (advanced usage) :param int volume: The play volume, in percent of maximum volume :param play_type: The behavior of ``speak`` once playback has been initiated :type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP`` :returns: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the spawn subprocess from ``subprocess.Popen``; ``None`` otherwise """

        self._validate_play_type(play_type)
        self.set_volume(volume)

        with open(os.devnull, 'w') as n:
            cmd_line = ['/usr/bin/espeak', '--stdout'] + shlex.split(espeak_opts) + [shlex.quote(text)]
            aplay_cmd_line = shlex.split('/usr/bin/aplay -q')

            if play_type == Sound.PLAY_WAIT_FOR_COMPLETE:
                espeak = Popen(cmd_line, stdout=PIPE)
                play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
                play.wait()

            elif play_type == Sound.PLAY_NO_WAIT_FOR_COMPLETE:
                espeak = Popen(cmd_line, stdout=PIPE)
                return Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)

            elif play_type == Sound.PLAY_LOOP:
                while True:
                    espeak = Popen(cmd_line, stdout=PIPE)
                    play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
                    play.wait()