You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. ## Respeaker Microphone Array
  2. In this tutorial, we will go over how to use Stretch's [Respeaker Mic Array v2.0](https://wiki.seeedstudio.com/ReSpeaker_Mic_Array_v2.0/).
  3. <p align="center">
  4. <img src="https://raw.githubusercontent.com/hello-robot/stretch_tutorials/noetic/images/respeaker.jpg"/>
  5. </p>
  6. ### Stretch Respeaker Tool
  7. We'll begin by using the command-line Stretch Respeaker Tool to quickly try out the robot's microphone array and speakers. This tool doesn't use ROS, but we'll cover how to use the Respeaker from ROS in the next section. Type the following command in a new terminal:
  8. ```{.bash .shell-prompt}
  9. stretch_respeaker_test.py
  10. ```
  11. The following will be outputted in your terminal:
  12. ```{.bash .no-copy}
  13. hello-robot@stretch-re1-1005:~$ stretch_respeaker_test.py
  14. For use with S T R E T C H (TM) RESEARCH EDITION from Hello Robot Inc.
  15. * waiting for audio...
  16. * recording 3 seconds
  17. * done
  18. * playing audio
  19. * done
  20. * waiting for audio...
  21. ```
  22. The Stretch Respeaker tool will wait until it hears audio loud enough to trigger VAD (voice activity detection). Then, the tool will record audio for 3 seconds, replay it through its speakers, and go back to waiting for audio. This tool is a good way to confirm the hardware is working correctly.
  23. To stop the tool, type **Ctrl** + **C** in the terminal.
  24. ### Respeaker ROS Package
  25. #### Prerequisite
  26. Before getting started with the Respeaker ROS package, we'll confirm it is available to use. Type the following into a new terminal:
  27. ```{.bash .shell-prompt}
  28. rospack find respeaker_ros
  29. ```
  30. If you get an error like `[rospack] Error: package 'respeaker_ros' not found`, refresh your ROS workspace using the [Creating a New ROS Workspace](https://github.com/hello-robot/stretch_install/blob/master/docs/ros_workspace.md) tutorial.
  31. #### Getting started
  32. Run the `respeaker.launch` file in a new terminal using:
  33. ```{.bash .shell-prompt}
  34. roslaunch respeaker_ros respeaker.launch
  35. ```
  36. This will bring up the necessary ROS nodes to interface with the robot's microphone array and speakers. After initialization, you will see the following outputted in your terminal:
  37. ```bash
  38. [INFO] [1672818306.618280]: Initializing Respeaker device (takes 10 seconds)
  39. [INFO] [1672818317.082498]: Respeaker device initialized (Version: 16)
  40. [INFO] [1672818317.521955]: Found 6: ReSpeaker 4 Mic Array (UAC1.0): USB Audio (hw:1,0) (channels: 6)
  41. [INFO] [1672818317.526263]: Using channels range(0, 6)
  42. ```
  43. Explore some of the notable ROS topics being published using the following commands:
  44. ```bash
  45. rostopic echo /audio # Raw audio data
  46. rostopic echo /speech_audio # Raw audio data when there is speech
  47. rostopic echo /sound_direction # Direction (in Degrees) of audio source
  48. rostopic echo /sound_localization # Direction (in Quaternion part of SE3 pose) of audio source
  49. rostopic echo /is_speeching # Result of Voice Activity Detector (VAD)
  50. rostopic echo /speech_to_text # Voice recognition
  51. ```
  52. #### Speech Recognition
  53. In particular, the `/speech_to_text` topic can be helpful for prototyping voice command based programs. In a new terminal, run `rostopic echo /speech_to_text`. Then, stand near the robot and say "hello robot". You will see something like this outputted to the terminal:
  54. ```bash
  55. transcript:
  56. - hello robot
  57. confidence: [0.9876290559768677]
  58. ```
  59. A internet connection is required since the audio is being transcribed by the Google Speech API. To switch to using offline transciption, you can swap the speech recognizer used in the [speech_to_text node](https://github.com/hello-binit/respeaker_ros/blob/4880cd50cb4b2272ca3221680632bdcf7390a978/scripts/speech_to_text.py#L73-L74). See the [SpeechRecognition docs](https://pypi.org/project/SpeechRecognition/) for other available speech recognizers.
  60. #### Direction of Arrival
  61. The `/sound_direction` and `/sound_localization` topics give the DOA, or direction of arrival, in degrees and quaternion respectively. New messages are published when the DOA changes. And the 12 Respeaker LEDs show the DOA coarsely by coloring the LED closest to the DOA teal, while the rest of the LEDs show a darker blue color. In a new terminal, run `rostopic echo /sound_direction` or `rostopic echo /sound_localization`. Then, stand in front of the robot and say anything. You will see something like this outputted to the terminal:
  62. ```bash
  63. # /sound_direction
  64. data: 0
  65. # or /sound_localization
  66. header:
  67. seq: 1
  68. stamp:
  69. secs: 1672863834
  70. nsecs: 646940469
  71. frame_id: "respeaker_base"
  72. pose:
  73. position:
  74. x: 0.0
  75. y: 0.0
  76. z: 0.0
  77. orientation:
  78. x: 0.0
  79. y: 0.0
  80. z: 1.0
  81. w: 0.0
  82. ```
  83. The DOA range in degrees is [-180, 180], and the diagram below shows the DOA range visually:
  84. ```
  85. TODO
  86. ```
  87. Due to echo-ing within the shell covering the Respeaker, the DOA can be inaccurate. If you are experiencing this issue, contact Hello Robot Support for instructions on removing the head shell, which will reduce echo. Furthermore, it's possible to get more accurate DOA with audio post-processing. The Respeaker calculates the DOA on-hardware, however audio streams from the four microphones are published, so it is possible to use real-time audio source localization software like [ODAS](https://wiki.seeedstudio.com/ReSpeaker_Mic_Array_v2.0/#realtime-sound-source-localization-and-tracking) to better determine the DOA.
  88. #### Dynamic Reconfigure
  89. You can also set various parameters via `dynamic_reconfigure`, by running the following command in a new terminal:
  90. ```{.bash .shell-prompt}
  91. rosrun rqt_reconfigure rqt_reconfigure
  92. ```