Browse Source

Fixed typos.

main
Alan G. Sanchez 2 years ago
parent
commit
2733c23ce9
1 changed files with 4 additions and 19 deletions
  1. +4
    -19
      example_8.md

+ 4
- 19
example_8.md View File

@ -2,19 +2,15 @@
This example will showcase how to save the interpreted speech from Stretch's [ReSpeaker Mic Array v2.0](https://wiki.seeedstudio.com/ReSpeaker_Mic_Array_v2.0/) to a text file. This example will showcase how to save the interpreted speech from Stretch's [ReSpeaker Mic Array v2.0](https://wiki.seeedstudio.com/ReSpeaker_Mic_Array_v2.0/) to a text file.
<p align="center"> <p align="center">
<img src="images/respeaker.jpg"/> <img src="images/respeaker.jpg"/>
</p> </p>
Begin by running the `sample_respeaker.launch` file in a terminal.
Begin by running the `respeaker.launch` file in a terminal.
```bash ```bash
# Terminal 1 # Terminal 1
roslaunch stretch_core respeaker.launch roslaunch stretch_core respeaker.launch
``` ```
Then run the speech_text node. Then run the speech_text node.
```bash ```bash
@ -22,7 +18,6 @@ Then run the speech_text node.
cd catkin_ws/src/stretch_tutorials/src/ cd catkin_ws/src/stretch_tutorials/src/
python speech_text.py python speech_text.py
``` ```
The ReSpeaker will be listening and will start to interpret speech and save the transcript to a text file. To stop shutdown the node, type **Ctrl** + **c** in the terminal. The ReSpeaker will be listening and will start to interpret speech and save the transcript to a text file. To stop shutdown the node, type **Ctrl** + **c** in the terminal.
### The Code ### The Code
@ -66,7 +61,6 @@ if __name__ == '__main__':
rospy.spin() rospy.spin()
``` ```
### The Code Explained ### The Code Explained
Now let's break the code down. Now let's break the code down.
@ -75,18 +69,15 @@ Now let's break the code down.
``` ```
Every Python ROS [Node](http://wiki.ros.org/Nodes) will have this declaration at the top. The first line makes sure your script is executed as a Python script. Every Python ROS [Node](http://wiki.ros.org/Nodes) will have this declaration at the top. The first line makes sure your script is executed as a Python script.
```python ```python
import rospy import rospy
import os import os
``` ```
You need to import rospy if you are writing a ROS Node.
You need to import `rospy` if you are writing a ROS [Node](http://wiki.ros.org/Nodes).
```python ```python
from speech_recognition_msgs.msg import SpeechRecognitionCandidates from speech_recognition_msgs.msg import SpeechRecognitionCandidates
``` ```
Import `SpeechRecognitionCandidates` from the `speech_recgonition_msgs.msg` so that we can receive the interpreted speech. Import `SpeechRecognitionCandidates` from the `speech_recgonition_msgs.msg` so that we can receive the interpreted speech.
```python ```python
@ -96,35 +87,29 @@ def __init__(self):
""" """
self.sub = rospy.Subscriber("speech_to_text", SpeechRecognitionCandidates, self.callback) self.sub = rospy.Subscriber("speech_to_text", SpeechRecognitionCandidates, self.callback)
``` ```
Set up a subscriber. We're going to subscribe to the topic "*speech_to_text*", looking for `SpeechRecognitionCandidates` messages. When a message comes in, ROS is going to pass it to the function "callback" automatically. Set up a subscriber. We're going to subscribe to the topic "*speech_to_text*", looking for `SpeechRecognitionCandidates` messages. When a message comes in, ROS is going to pass it to the function "callback" automatically.
```python ```python
self.save_path = '/home/hello-robot/catkin_ws/src/stretch_tutorials/stored_data self.save_path = '/home/hello-robot/catkin_ws/src/stretch_tutorials/stored_data
``` ```
Define the directory to save the text file. Define the directory to save the text file.
```python ```python
transcript = ' '.join(map(str,msg.transcript)) transcript = ' '.join(map(str,msg.transcript))
``` ```
Take all items in the iterable list and join them into a single string named transcript. Take all items in the iterable list and join them into a single string named transcript.
```python ```python
file_name = 'speech.txt' file_name = 'speech.txt'
completeName = os.path.join(self.save_path, file_name) completeName = os.path.join(self.save_path, file_name)
``` ```
Define the file name and create a complete path directory. Define the file name and create a complete path directory.
```python ```python
with open(completeName, "a+") as file_object: with open(completeName, "a+") as file_object:
file_object.write("\n") file_object.write("\n")
file_object.write(transcript) file_object.write(transcript)
``` ```
Append the transcript to the text file. Append the transcript to the text file.
```python ```python
@ -132,9 +117,9 @@ rospy.init_node('speech_text')
SpeechText() SpeechText()
``` ```
The next line, `rospy.init_node(NAME, ...)`, is very important as it tells rospy the name of your node -- until rospy has this information, it cannot start communicating with the ROS Master. In this case, your node will take on the name talker. NOTE: the name must be a base name, i.e. it cannot contain any slashes "/".
The next line, `rospy.init_node(NAME, ...)`, is very important as it tells rospy the name of your node -- until rospy has this information, it cannot start communicating with the ROS Master. **NOTE:** the name must be a base name, i.e. it cannot contain any slashes "/".
Instantiate the class with `SpeechText()`
Instantiate the `SpeechText()` class.
```python ```python
rospy.spin() rospy.spin()

Loading…
Cancel
Save