示例#1
0
 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()
示例#2
0
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"])
示例#3
0
def playCaptcha(phrase):	
	speech = Text(phrase).speech()
	speech.audio.play()
示例#4
0
	def test_create_no_argument(self):
		with pytest.raises(TypeError):
			t = Text()
示例#5
0
	def test_speech_empty_string(self):
		with pytest.raises(APIException):
			Text("").speech()
示例#6
0
	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
示例#7
0
	def test_interpret_empty_string(self):
		with pytest.raises(APIException):
			Text("").interpret()
示例#8
0
	def test_interpret(self):
		t = Text("hello")
		i = t.interpret()
		assert isinstance(i, Interpret)
		assert i.intent == "greeting"
示例#9
0
	def test_speech(self):
		with pytest.raises(APIException):
			Text("test").speech()
示例#10
0
	def test_interpret(self):
		with pytest.raises(APIException):
			Text("test").interpret()
示例#11
0
	def test_create(self):
		t = Text("test")
		assert isinstance(t, Text)
		assert t.text == "test"
示例#12
0
 def text(self):
     """ Convert speech to text and get the prediction """
     from auroraapi.text import Text
     return Text(get_stt(self.audio)["transcript"])
示例#13
0
 def play_text_callback(text, *largs):
     Text(text).speech().audio.play()