| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2016, Jon Hawkesworth (@jhawkesworth) <[email protected]> |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
DOCUMENTATION = r''' |
| 8 |
--- |
| 9 |
module: win_say |
| 10 |
short_description: Text to speech module for Windows to speak messages and optionally play sounds |
| 11 |
description: |
| 12 |
- Uses .NET libraries to convert text to speech and optionally play .wav sounds. Audio Service needs to be running and some kind of speakers or |
| 13 |
headphones need to be attached to the windows target(s) for the speech to be audible. |
| 14 |
options: |
| 15 |
msg: |
| 16 |
description: |
| 17 |
- The text to be spoken. |
| 18 |
- Use either C(msg) or C(msg_file). |
| 19 |
- Optional so that you can use this module just to play sounds. |
| 20 |
type: str |
| 21 |
msg_file: |
| 22 |
description: |
| 23 |
- Full path to a windows format text file containing the text to be spoken. |
| 24 |
- Use either C(msg) or C(msg_file). |
| 25 |
- Optional so that you can use this module just to play sounds. |
| 26 |
type: path |
| 27 |
voice: |
| 28 |
description: |
| 29 |
- Which voice to use. See notes for how to discover installed voices. |
| 30 |
- If the requested voice is not available the default voice will be used. |
| 31 |
Example voice names from Windows 10 are C(Microsoft Zira Desktop) and C(Microsoft Hazel Desktop). |
| 32 |
type: str |
| 33 |
speech_speed: |
| 34 |
description: |
| 35 |
- How fast or slow to speak the text. |
| 36 |
- Must be an integer value in the range -10 to 10. |
| 37 |
- -10 is slowest, 10 is fastest. |
| 38 |
type: int |
| 39 |
default: 0 |
| 40 |
start_sound_path: |
| 41 |
description: |
| 42 |
- Full path to a C(.wav) file containing a sound to play before the text is spoken. |
| 43 |
- Useful on conference calls to alert other speakers that ansible has something to say. |
| 44 |
type: path |
| 45 |
end_sound_path: |
| 46 |
description: |
| 47 |
- Full path to a C(.wav) file containing a sound to play after the text has been spoken. |
| 48 |
- Useful on conference calls to alert other speakers that ansible has finished speaking. |
| 49 |
type: path |
| 50 |
notes: |
| 51 |
- Needs speakers or headphones to do anything useful. |
| 52 |
- | |
| 53 |
To find which voices are installed, run the following Powershell commands. |
| 54 |
|
| 55 |
Add-Type -AssemblyName System.Speech |
| 56 |
$speech = New-Object -TypeName System.Speech.Synthesis.SpeechSynthesizer |
| 57 |
$speech.GetInstalledVoices() | ForEach-Object { $_.VoiceInfo } |
| 58 |
$speech.Dispose() |
| 59 |
|
| 60 |
- Speech can be surprisingly slow, so it's best to keep message text short. |
| 61 |
seealso: |
| 62 |
- module: community.windows.win_msg |
| 63 |
- module: community.windows.win_toast |
| 64 |
author: |
| 65 |
- Jon Hawkesworth (@jhawkesworth) |
| 66 |
''' |
| 67 |
|
| 68 |
EXAMPLES = r''' |
| 69 |
- name: Warn of impending deployment |
| 70 |
community.windows.win_say: |
| 71 |
msg: Warning, deployment commencing in 5 minutes, please log out. |
| 72 |
|
| 73 |
- name: Using a different voice and a start sound |
| 74 |
community.windows.win_say: |
| 75 |
start_sound_path: C:\Windows\Media\ding.wav |
| 76 |
msg: Warning, deployment commencing in 5 minutes, please log out. |
| 77 |
voice: Microsoft Hazel Desktop |
| 78 |
|
| 79 |
- name: With start and end sound |
| 80 |
community.windows.win_say: |
| 81 |
start_sound_path: C:\Windows\Media\Windows Balloon.wav |
| 82 |
msg: New software installed |
| 83 |
end_sound_path: C:\Windows\Media\chimes.wav |
| 84 |
|
| 85 |
- name: Text from file example |
| 86 |
community.windows.win_say: |
| 87 |
start_sound_path: C:\Windows\Media\Windows Balloon.wav |
| 88 |
msg_file: AppData\Local\Temp\morning_report.txt |
| 89 |
end_sound_path: C:\Windows\Media\chimes.wav |
| 90 |
''' |
| 91 |
|
| 92 |
RETURN = r''' |
| 93 |
message_text: |
| 94 |
description: The text that the module attempted to speak. |
| 95 |
returned: success |
| 96 |
type: str |
| 97 |
sample: "Warning, deployment commencing in 5 minutes." |
| 98 |
voice: |
| 99 |
description: The voice used to speak the text. |
| 100 |
returned: success |
| 101 |
type: str |
| 102 |
sample: Microsoft Hazel Desktop |
| 103 |
voice_info: |
| 104 |
description: The voice used to speak the text. |
| 105 |
returned: when requested voice could not be loaded |
| 106 |
type: str |
| 107 |
sample: Could not load voice TestVoice, using system default voice |
| 108 |
''' |