You can add small audio files (<100kB) to your MegunoLink project and play them on your computer by sending serial commands from your Arduino. Or have MegunoLink speak text using the system speech synthesizer.
To play sounds with serial commands:
- import a
.wav
file into your MegunoLink project, then - create an
Audio
variable in your Arduino sketch and use itsPlayAudioClip
method to play the sound.
To speak text with commands:
- create an
Audio
variable in your Arduino sketch and use itsSpeak
method to send the text you want spoken.
Importing Audio Files
Select Manage Audio Clips from the gear (⚙) menu to add, rename, delete and test audio clips in your MegunoLink project. Clips are stored in the project file so they are always available.
Import a new clip by clicking Add and browsing to the location of the audio clip. The audio clip must be a .wav
and less than 100kB. You can download useful audio clips from websites such as free sound.
The default name for newly imported audio clips is their filename, however you can change this by selecting the clip in the clip-list and clicking the Rename button. This name is used when sending commands to MegunoLink to play the audio clip.
Audio clips can be removed from your project by clicking the Delete button.
Select a clip and click the Play button to play the clip. Use the Stop button to stop long running audio clips.
Triggering Playback
Create an Audio
variable with our Arduino library and use its PlayAudioClip
method to trigger playback of an audio clip loaded into your MegunoLink project. The clip will play back on your computer’s speakers.
1 2 3 4 5 6 7 |
#include "MegunoLink.h" void TriggerRoar() { Audio Sounds; Sounds.PlayAudioClip(F("Roar")); } |
Configuring the Speech Synthesizer
Select Text to Speech Settings from the gear (⚙) menu to change the settings used to synthesize speech from text. The settings available may vary depending on the voices you have installed. Click Open system speech settings to launch the system speech settings to manage voices installed on your computer.
The Speaking rate controls how fast the text is spoken. The volume controls how loud the speech is, relative to the system volume setting. Select from installed speakers using the voice control. Click the Test button to speak a short text passage with the selected settings.
Speak a message
Create an Audio
variable with our Arduino library and use its Speak
method to speak a message. The speech will play back on your computer’s speakers.
1 2 3 4 5 6 7 |
#include "MegunoLink.h" void ReportWorkFinished() { Audio Sounds; Sounds.Speak(F("Jobs done")); } |
Arduino library reference
The Audio
definition is found in our Arduino library. The library sends the serial commands that MegunoLink will recognize to trigger playback of audio clips loaded into your project or speak text.
Methods
An Audio
variable has the following methods:
Method Descriptions
Audio Constructor
Creates a Audio
variable, which can be used to send commands to MegunoLink to trigger playback of audio files.
Audio(Print &Destination = Serial);
Name | Type | Required? | Description |
---|---|---|---|
Destination | Print & | No | Sets the serial connection to use for sending messages to MegunoLink. Defaults to Serial , the default Arduino RS232 port. |
1 2 3 4 |
#include "MegunoLink.h" Audio Sounds1; // send commands to MegunoLink using default (Serial) port. Audio Sounds2(Serial1); // send commands to MegunoLink using Serial1 port. |
Play audio clip
Sends a command to MegunoLink to trigger playback of a named audio clip.
PlayAudioClip(const char* ClipName);
PlayAudioClip(const __FlashStringHelper* ClipName);
PlayAudioClip(const String* ClipName);
1 2 |
Sounds1.PlayAudioClip("Roar"); Sounds1.PlayAudioClip(F("Birds")); |
Name | Type | Required? | Description |
---|---|---|---|
ClipName | const char*, const __FlashStringHelper*, String | Yes | The name of the clip to play. |
Speak text
Sends a command to MegunoLink to speak a message.
Speak(const char* Message);
Speak(const __FlashStringHelper* Message);
Speak(const String* Message);
1 2 |
Sounds1.Speak("I am an Arduino"); Sounds1.Speak(F("I compute therefore I am")); |
Name | Type | Required? | Description |
---|---|---|---|
Message | const char*, const __FlashStringHelper*, String | Yes | The text to speak. |