def execute(self, context, edge): text = Text() while len(text.text) == 0: text = listen_and_transcribe(**self.listen_settings) res = text.interpret(model=self.model) if self.interpret else text context.set_step_data(self.step_name, res) return edge.next()
def listen_and_transcribe(length=0, silence_len=0.5): """ Listen with the given parameters, but simulaneously stream the audio to the Aurora API, transcribe, and return a Text object. This reduces latency if you already know you want to convert the speech to text. :param length the length of time (seconds) to record for. If 0, it will record indefinitely, until the specified amount of silence :type length float :param silence_len the amount of silence (seconds) to allow before stoping (ignored if length != 0) :type silence_len float """ from auroraapi.text import Text return Text(get_stt(functools.partial(stream, length, silence_len), stream=True)["transcript"])
def playCaptcha(phrase): speech = Text(phrase).speech() speech.audio.play()
def test_create_no_argument(self): with pytest.raises(TypeError): t = Text()
def test_speech_empty_string(self): with pytest.raises(APIException): Text("").speech()
def test_speech(self): t = Text("hello") s = t.speech() assert isinstance(s, Speech) assert isinstance(s.audio, AudioFile) assert len(s.audio.audio) > 0
def test_interpret_empty_string(self): with pytest.raises(APIException): Text("").interpret()
def test_interpret(self): t = Text("hello") i = t.interpret() assert isinstance(i, Interpret) assert i.intent == "greeting"
def test_speech(self): with pytest.raises(APIException): Text("test").speech()
def test_interpret(self): with pytest.raises(APIException): Text("test").interpret()
def test_create(self): t = Text("test") assert isinstance(t, Text) assert t.text == "test"
def text(self): """ Convert speech to text and get the prediction """ from auroraapi.text import Text return Text(get_stt(self.audio)["transcript"])
def play_text_callback(text, *largs): Text(text).speech().audio.play()