|
@@ -37,14 +37,15 @@ The constructor has a __**kwargs argument__ which is corresponding to the Dict o
|
|
1. Attach the incoming callback to the self.main_controller_callback attribute. This callback come from the main controller and will receive the text at the end of the process
|
|
1. Attach the incoming callback to the self.main_controller_callback attribute. This callback come from the main controller and will receive the text at the end of the process
|
|
1. Obtain audio from the microphone in the constructor. (Note : we mostly use the [speech_recognition library](https://pypi.python.org/pypi/SpeechRecognition/))
|
|
1. Obtain audio from the microphone in the constructor. (Note : we mostly use the [speech_recognition library](https://pypi.python.org/pypi/SpeechRecognition/))
|
|
1. Set your callback method into the mother class with `self.set_callback(self.google_callback)`. This callback is the one which will process the audio into a text.
|
|
1. Set your callback method into the mother class with `self.set_callback(self.google_callback)`. This callback is the one which will process the audio into a text.
|
|
-1. Use self.start_listening() from the mother class to get an audio. Once caught, the mother class will give the audio stream to the callback you've set before.
|
|
|
|
-1. The callback method must implement two arguments: recognizer and audio. The audio argument contains the stream caught by the microphone
|
|
|
|
|
|
+1. Use self.start_processing() from the mother class to get an audio from the microphone or read the audio file path if provided. The mother class will give the audio stream to the callback you've set before.
|
|
|
|
+1. The callback method must implement two arguments: recognizer and audio. The audio argument contains the stream caught by the microphone or read from an audio file path
|
|
1. Do magic stuff with the audio in order to get a string that contains the translated text
|
|
1. Do magic stuff with the audio in order to get a string that contains the translated text
|
|
1. Once you get the text, let give it to the main_controller_callback method received in the constructor by calling it with the text string as argument `self.main_controller_callback(audio_to_text)`
|
|
1. Once you get the text, let give it to the main_controller_callback method received in the constructor by calling it with the text string as argument `self.main_controller_callback(audio_to_text)`
|
|
|
|
|
|
```python
|
|
```python
|
|
def __init__(self, callback=None, **kwargs):
|
|
def __init__(self, callback=None, **kwargs):
|
|
- OrderListener.__init__(self)
|
|
|
|
|
|
+ # give the audio file path to process directly to the mother class if exist
|
|
|
|
+ SpeechRecognition.__init__(self, kwargs.get('audio_file_path', None))
|
|
# here is the main controller callback. We will return the text at the end of the process
|
|
# here is the main controller callback. We will return the text at the end of the process
|
|
self.main_controller_callback = callback
|
|
self.main_controller_callback = callback
|
|
|
|
|
|
@@ -52,8 +53,8 @@ The constructor has a __**kwargs argument__ which is corresponding to the Dict o
|
|
|
|
|
|
# give our callback
|
|
# give our callback
|
|
self.set_callback(self.my_callback)
|
|
self.set_callback(self.my_callback)
|
|
- # start the microphone to capture an audio
|
|
|
|
- self.start_listening()
|
|
|
|
|
|
+ # start processing, record a sample from the microphone if no audio file path provided, else read the file
|
|
|
|
+ self.start_processing()
|
|
|
|
|
|
def my_callback((self, recognizer, audio):
|
|
def my_callback((self, recognizer, audio):
|
|
# ---------------------------------------------
|
|
# ---------------------------------------------
|