About audio playback

Hello,

I need a script. What I want this script to do is
First: I want him to speak the text I wrote. (play as sound)
Second: I want it to play an audio file that I specify on the computer.
If both I want cannot be done in one code. Can you share this in two different codes?

Can you help with this.

I wish you good work.
Kind regards.

Hi @hguler07,

Thanks for your script request. We have asked our script developers to check and provide their input.

Kind Regards,
PremJK

Hi @hguler07

If you (and others) may find it useful, I have a script that does what you described.

Update - v0.9 - 9/8/2021

  • Added ability to change main system volume
    • New Config: Main_System_Volume
      • Default: 50
      • System Volume. 0 is lowest, 100 is loudest
    • New Config: Main_System_Mute_Volume
      • Default: 0
      • Mute System Volume (Enable =1, Disable=0)
  • Added ability to update PowerShell and .NET to latest supported versions if current system is below requirements
    • New Config: Powershell_Update_Reboot
      • Default: 0
      • Automatically Reboot if PowerShell is updated (Enable=1,Disable=0)
      • Note: If PowerShell version detected is lower than v3, it is automatically updated to 5.1 along with .net 4.5. A reboot is required, after which the script will run as normal
  • Improved ability to detect current systems audio configuration and hardware
    • If no audio hardware is detected, or otherwise an issue is detected with it, the script will log any errors and quit
  • Added ability to use VLC media player to play audio files
    • New Config: Use_VLCPlayer
      • Default: 1
      • Use VLC to Play Media(Enable =1, Disable=0)
    • Note: If enabled, VLC will automatically be installed silently via chocolatey. When using VLC, Play_Audio_Volume no longer works. Use Main_System_Volume to control playback volume. Using VLC will help solve compatibility issues, otherwise the script uses the Windows MediaPlayer class which should work well for most use cases
  • Script is now fully compatible and tested with Windows 7
  • Added ability to use google share drive URLs to download audio files
    • Note: The method to automatically retrieve the file name is a bit hacky, so any changes Google makes to share URLs could break this
  • Fixed an issue where downloaded files would sometimes not be removed when Keep_download_file was enabled
  • Improved logging detail and error handling
  • Other various fixes and improvements
Update - v0.5 - 9/3/2021
  • Added ability to specify volume level for TTS
    • New Config: text_to_Speech_Volume
      • Default: 50
      • 0 is lowest (mute), 100 is loudest
  • Added ability to specify volume level for playing audio files
    • New Config: Play_Audio_Volume
      • Default: 50
      • 0 is lowest (mute), 100 is loudest
  • Added ability to use URL for Play_Audio_Path to download audio files
    • New Config: Audio_Download_Location
      • Default: C:\Audio
      • Folder where the file will be downloaded if Play_Audio_Path is a valid URL
    • New Config: Keep_Downloaded_File
      • Default: 0
      • Whether to keep download file after playing. (1=Enabled,0=Disabled)
  • Added ability to enable or disable the Playing Now windows notification
    • New Config: Now_Playing_Notification
      • Default: 0
      • Display Now Playing Notification. (1=Enabled,0=Disabled)
  • Added ability to enable log file output for logging detail run history and errors
    • New Config: Enable_Log
      • Default: 1
      • Create log file of actions, history and errors. (1=Enabled,0=Disabled)
    • New Config: LogFile_Directory
      • Default: C:\Logs
      • Directory where log file should be created
Update - v0.3 - 9/1/2021
  • Updated python to launch PowerShell using 'Set-ExecutionPolicy Bypass' to help resolve script access denied errors
  • Fixed an issue where no audio files would play if Play_Audio_Path contained invalid characters
  • Added the ability to toggle playing audio files by configuring parameter Play_Audio. Default: 0 (Enable=1, Disable=0)
  • Changed Play_Audio_Filter to accept only file extension names (no wildcards or filenames). This is to resolve an issue related to paths with invalid characters
Information
  • This is a powershell script executed from python, as such it can only be run on Windows Endpoints
  • Requires Powershell v3 or higher
  • Tested working on Windows 10
Installation for iTarian Procedures
  • Download the procedure:
  • Within your ITSM portal, import the procedure under Configuration Templates - Procedures
  • Configure desired procedure name, alert settings..etc
  • Configure the default parameters for the procedure from the Parameters tab of the script. See Configuration Parameters below for explanations of each parameter
  • Click Save - Ready to Review - Approve to finish. Assign to a profile and optionally a schedule of your liking
  • (Recommended) Run the new procedure on a single test machine to ensure its working or configured as expected
  • This script can be run either as LocalUser or LocalSystem
Configuration Parameters

Text_to_Speak

  • Default: Hello. This is a test message spoken from Windows Speech Synthesizer. Thank you
  • This is the phrase that should be spoken by Text-to-Speech
Text_to_Speech_Speed
  • Default: 0
  • This is the speed of Text-to-Speech. -10 is slowest, 10 is fastest, 0 is normal
Text_to_Speech_Volume
  • Default: 50
  • 0 is lowest (mute), 100 is loudest
Main_System_Volume
  • Default: 50
  • Main System Volume Control. 0 is lowest, 100 is loudest
Main_System_Mute_Volume
  • Default: 0
  • Mute System Volume Control (Enable =1, Disable=0)
Play_Audio
  • Default: 0 (Enable=1, Disable=0)
  • Play Audio From File(s). If disabled, the rest of the parameters below are ignored
Play_Audio_Path
  • Default: C:\Audio\Announcement.mp3
  • Path to audio file(s) to be played. You can specify a folder or a single file. If a folder, all compatible audio files in that folder will be played that match the Play_Audio_Filter
  • Any value entered that does not resolve to a valid path disables playing audio files
Play_Audio_Filter
  • Default: mp3,wma,wav,flac
  • Audio file extensions allowed to be played. Comma separated
  • Example: If you specify a folder with multiple audio files, but only wish to play MP3's in that folder, then enter: mp3 Example 2: If you specify a folder with multiple audio files, but only wish to play WAV and MP3 files, then enter: mp3,wav
  • Note: Compatible files depends on what is supported by Windows Media Player on the endpoint
Play_Audio_Volume
  • Default: 50
  • 0 is lowest (mute), 100 is loudest
Audio_Download_Location
  • Default: C:\Audio
  • Folder where the file will be downloaded if Play_Audio_Path is a valid URL
Keep_Downloaded_File
  • Default: 0
  • Whether to keep download file after playing. (1=Enabled,0=Disabled)
Now_Playing_Notification
  • Default: 0
  • Display Now Playing Notification. (1=Enabled,0=Disabled)
Use_VLCPlayer
  • Default: 1
  • Use VLC to Play Media(Enable =1, Disable=0)
  • Note: If enabled, VLC will automatically be installed silently via chocolatey. When using VLC, Play_Audio_Volume no longer works. Use Main_System_Volume to control playback volume. Using VLC will help solve compatibility issues, otherwise the script uses the Windows MediaPlayer class which should work well for most use cases
Shuffle
  • Default: 0
  • Enables random shuffle if playing multiple files from a folder (1 = Enabled, 0 = Disabled)
Enable_Log
  • Default: 1
  • Create log file of actions, history and errors. (1=Enabled,0=Disabled)
LogFile_Directory
  • Default: C:\Logs
  • Directory where log file should be created
Powershell_Update_Reboot
  • Default: 0
  • Automatically Reboot if PowerShell is updated (Enable=1,Disable=0)
  • Note: If PowerShell version detected is lower than v3, it is automatically updated to 5.1 along with .net 4.5. A reboot is required, after which the script will run as normal
Feel free to use or edit to your liking. I can also make requested adjustments, depending on the request. I hope it can be of some use.

Thanks!

EZT-AudioPlayer.json (91.7 KB)

Hi @eztech

All I can say for the script you shared with us is wow…! thank you.

I checked the file, I checked the computer I use in the institution and I got an error message even though it worked successfully. iTarian RMM- Executing Powershell Script access denied. Maybe that’s why I didn’t hear any sound.

in the parts of the code that can enter parameters. For example, if I just want it to say I’m typing, should I leave the audio path parameter blank?

and actually there were a few features that I wanted to have in this request code file, but I didn’t specify it above exactly.

The majority of windows 7 and windows 10 machines in the institution are windows 7. I hope this code will work on both operating systems.

and I hope to be able to download and run the audio file via a url like google driver.

I look forward to updates on the subject.

I wish you good work.
Kind regards

Hi @eztech,

Thank you so much for sharing your script. We appreciate your efforts.

Kind Regards,
PremJK

I’m glad its what your looking for, but I’m sorry its not working for you. Lets see if we can fix that.

I’m unsure exactly why it would say access denied. I see you ran it as localuser and localsystem. Some questions:

  • Did you get the access denied error in both cases (running as localuser and localsystem?)
  • Was that test machine Windows 7 or 10?
[quote="hguler07,post:4,topic:53502"]

in the parts of the code that can enter parameters. For example, if I just want it to say I’m typing, should I leave the audio path parameter blank?

[/quote]

If you do not wish to play any audio from a file, you can enter anything in that parameter that is not a valid path to a file or folder. Unfortunately iTarian parameters don’t seem to allow blank values (would be nice if that could be allowed). So probably the easiest thing to do when you don’t want to play an audio file is to just enter “$null” (no quotes) for that parameter. You can also just put “none” or whatever works best. If too confusing, I can add a parameter for enabling and disabling of playing audio from files

My access to Windows 7 machines are quite limited these days, so its harder for me to test on them. But I can probably spin up a Win7 VM for testing. Technically, as long as Powershell v3 is installed, and Windows Media Player, it “should” work. If you have a bunch of Win7 machines, then it may be best to have you test for me and I can adjust accordingly.

As for adding the ability to download and play an audio file from a URL, that should be doable and I will add it to my feature list to implement.

First however, I think getting it working and resolving the Script Access Denied issue will be the focus. Are you comfortable making a small change to the script code? Try this.

  1. Open the procedure and click on the “View Procedure” tab.
  2. Click EDIT, so we can make changes.
  3. Scroll down to the very bottom of the script. We want to edit line 235 which should read:
ecmd('powershell "Set-ExecutionPolicy RemoteSigned"')
  1. We want to change just 1 word. Change “RemoteSigned” to “Bypass”

  2. The final change would look like this

  3. Click Save, then Read to Review, then Approve. Then test the script

This change will tell python to launch powershell and set the executionpolicy to bypass, in order to run remote code. That could be why your getting access denied. Try this and let me know. If that doesn’t solve it, we can troubleshoot further

@hguler07

I went ahead and updated the script with the change I outlined above, along with a few other changes/fixes I uncovered with some additional testing. Changes are below. I also edited my original post above with these changes (including updated instructions/descriptions) and attached the updated procedure file.

Update - v0.3 - 9/1/2021

  • Updated python to launch PowerShell using 'Set-ExecutionPolicy Bypass' to help resolve script access denied errors
  • Fixed an issue where no audio files would play if Play_Audio_Path contained invalid characters
  • Added the ability to toggle playing audio files by configuring parameter Play_Audio. Default: 0 (Enable=1, Disable=0)
  • Changed Play_Audio_Filter to accept only file extension names (no wildcards or filenames). This is to resolve an issue related to paths with invalid characters
  • Download: EZT-AudioPlayer.json
I'll hold off on adding the ability to download audio files from a URL until I've heard back from you that this version is working

EZT-AudioPlayer.json (14.8 KB)

Hello,

Thank you very much for your update on the subject.

I took a look at the topics you mentioned and tried the code you just shared. I keep getting access denied error on my own computer. I access the comodo dragon platform from 192.168.1.1 computer and send the script file to my own computer, 192.168.1.1. I don’t know if this will have any effect, just wanted to point out.

Additionally, I’m trying this on my roommate’s computer. His and my computer are windows 10. He spoke the text I typed on his computer without any problems.

Second, I tried to play the audio file. This time the code was successful, no access denied. However, it did not play the audio file I specified. I tried this on both computers, still the result did not change.

On my own computer, I thought that the problem with access is related to the police settings of the computer, I made the following change, but the result did not change. Administrator approval mode (disabled) for built-in administrator account

What can i do to fix this problem. Do you have any other suggestions? I am attaching the relevant screenshots.

3.JPG

For this issue, the reason it did not play the audio file is because the Play_Audio parameter is still set to 0. I added this new parameter with the updated version per the notes above. Set that to 1 and it should then try to play the audio file you specify with Play_Audio_Path.

As for the access denied error on your computer, there must be some kind of policy setting or perhaps permission issue preventing it from running. The procedure creates the powershell script in the temp directory of windows. If you run it as localsystem, that would normally be C:\Windows\Temp. If you run it as localuser, it would normally be c:\username\appdata\local emp. Could it be that there is a permission problem with the temp directory on your computer? Though if this was the case it would seem likely you would be having many other issues.

Also might be worth checking if any group policy settings are applied that could be causing the issue. Right click the start icon, select run, type rsop.msc and hit enter. This will show all of the policies applied to your computer, and check to see if any might be blocking running scripts. Alternatively, from a command prompt or powershell console, type GPRESULT /R to see a summary of applied policy settings

Here is a slightly alternate version of the procedure, that doesn’t use the temp directory and unblocks the created powershell file. I’m not very confident it will work as I’m unsure what the issue with your machine actually is, but might be worth a try

EZT-AudioPlayer-V2.json (16.6 KB)

Another test for the machine giving you an access denied error.

Try opening powershell (run as admin) and try running this code:

PowerShell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(' hello');"

If successful it should speak “hello”. This is just to test that Speech Synthesizer is working correctly, removing the scripts/procedure as a potential point of failure

Hello, I tried the script file you shared. I changed the parameter value to 1 as you indicated. I tried it on the computer that was playing the text in my room. It didn’t ring at first. Then I manually played that song on the computer once with the groove music application in windows. In my next post, the audio file was played successfully, I was very happy :slight_smile: we succeeded, this script is working.

I just don’t understand why it doesn’t work on my computer. My computer is not in the domain and I use my computer with admin rights.

I have full control rights over the file paths you specify.
When I sent this code to a windows 7 machine, I got an access denied error. It gets stuck in a small place but I don’t fully understand the problem. If we can suppress the execution of this code file to any log file, maybe we can see where it is stuck and where you get an error.

Can we add an area to this script where we can adjust the volume of the computer? When we enter 0 as a parameter, there is no sound. When we enter 100, the sound seems to be at the highest level.

I am sharing the relevant screenshots with you.
Thank you very much for your interest and help.

When I sent the script code to the first computer, it gave a warning like this, but no sound was played.

the output of the code was like this, duration part shows 0

Then I run the audio file manually on the computer from the groove music application. When I sent the code again, the sound started to play. The output of the code is as follows

Unfortunately, when I sent this code to my own computer, it still didn’t run the sound file.

2.JPG

GPRESULT /R screen output

file permissions screenshot

it was really the best way of understanding. There is a problem on my computer but I don’t know how to solve it

Ah I think we are getting somewhere. The problem is related to the Speech Synthesizer specifically on your system. I wonder if it could be related to language. I might guess the same would apply to the Windows 7 machine, as its trying to access a speech language thats not installed or configured.

In windows, go to settings, Time & Language, then Speech

On that page make sure you have a voice packaged installed. You can click add voices if none are installed. I understand English is not your native language, but perhaps try adding that if not already for testing

Here is an example (from my machine, which is English)

Also to clarify, the setting for Play_Audio parameter does not control volume. Setting to 1 enables playing audio from the file. Setting to 0 disables playing audio from the file. I apologize if adding that option added confusion. I will look into adding volume control as a new feature.

The “Now Playing” pop-up you saw was not a warning or error. It is an intended notification when an audio file starts playing. If you don’t want this, I can add an option to disable it.

Its odd that the audio does not play the first time in your tests, but will the second time you run the script or first open it in Groove. I wonder if setting your default music player to Windows Media player instead would help. I admit I’m at a loss on this one

Normally when I develop scripts, I include some detail logging and debugging options, it just so happens I did not for this one as it was put together quickly. I’ll be adding that logging to future versions

Thanks for your patience. I developed this script for someone that had a very small use case where they wanted a per-recorded message to play with the ability to customize a greeting using Text-to-Speech. As such, it hasn’t been fully developed, however I’m happy to work on it more if you don’t mind continuing to test and provide feedback.

My computer language is Turkish. I just checked the information you shared. I looked at the settings - region, language and speech section of the computer where the voiceover works fine and compared it with my own settings, both seem the same.

I ran the powershell code you shared with me on that computer, and it gave an error on that computer, but I could speak the text I wanted on this computer. I’m a bit confused then the problem is elsewhere.

It would be nice if we could grab the sound notification in this code file and add a parameter to control the sound level.

I’m going to try a little to solve this access denied problem, I’ll definitely let you know if I can manage.

If there’s a script or anything you want me to try, I’ll be happy to try it.

computer where this text and audio file run smoothly

this is my machine, i downloaded the english language too, it still didn’t fix

@hguler07

I sent you a forum DM where we can continue troubleshooting. I will post any updates/new versions of the script here

Hello @eztech

Yes I saw the DM message and suggested solutions for my problem. I tried all of them and still couldn’t find a solution. I was a little bored, so I turned off the computer and went for a walk on the beach. Then I suddenly got a flash of light and thought that there might be a problem with my profile. Because I was playing profiler features to test the abilities of comodo.

I moved myself to a normal profile. I sent the code to my computer and bingo both the audio file and the read aloud feature worked :slight_smile:

it was purely my curiosity and a problem that I didn’t know what I activate :frowning: so I was a bit embarrassed, we tried to solve a non-existent problem in vain :frowning:

This is the feature that I activated in my profile and caused the problem,

code now works

Now we can move on to the next step :slight_smile:

  • Turn off sound notification (disable)
  • adjust volume (0 - 100)
  • make it work on windows 7 computers
  • download audio file via url

I’m looking forward to the developments :slight_smile:

I wish you good work
Best regards

I’m very happy to hear it is now working! Sometimes the best thing to do is go for a walk and come back to the problem later. Especially a walk on the beach, for which I’m jealous :slight_smile:

I’m already working on the next version with the features requested. If not today, it should be ready tomorrow

@hguler07

I have uploaded a new version that contains the new features you requested as well as some other changes. I’ve updated the main post with the new info, but here also are the changes

Update - v0.5 - 9/3/2021

  • Added ability to specify volume level for TTS
    • New Config: text_to_Speech_Volume
      • Default: 50
      • 0 is lowest (mute), 100 is loudest
  • Added ability to specify volume level for playing audio files
    • New Config: Play_Audio_Volume
      • Default: 50
      • 0 is lowest (mute), 100 is loudest
  • Added ability to use URL for Play_Audio_Path to download audio files
    • New Config: Audio_Download_Location
      • Default: C:\Audio
      • Folder where the file will be downloaded if Play_Audio_Path is a valid URL
    • New Config: Keep_Downloaded_File
      • Default: 0
      • Whether to keep download file after playing. (1=Enabled,0=Disabled)
  • Added ability to enable or disable the Playing Now windows notification
    • New Config: Now_Playing_Notification
      • Default: 0
      • Display Now Playing Notification. (1=Enabled,0=Disabled)
  • Added ability to enable log file output for logging detail run history and errors
    • New Config: Enable_Log
      • Default: 1
      • Create log file of actions, history and errors. (1=Enabled,0=Disabled)
    • New Config: LogFile_Directory
      • Default: C:\Logs
      • Directory where log file should be created
Notes I've tested the procedure successfully on Windows 10 Pro (4 machines) and Windows 7 Pro (1 machine). The Win 7 testing is limited but hopefully you can confirm on your win 7 machines.

The script now uses my standard template for logging and error handling, which is enabled by default (See Enable_log). You can disable this or change the location where the log file is created. If you have issues, please share with me the log file (through forum DM) which will help greatly with troubleshooting.

Please make sure to review all config parameters and adjust to your needs, as there are both new ones and some defaults have changed. For example:

  • Play_Audio_Path default setting is now a URL to a sample mp3 file.
    • To play files from a local path, enter a local UNC path.
    • To download and play from the web, enter a valid URL to an audio file.
      • The file will be downloaded to the path set in Audio_Download_Location.
  • The setting Keep_Downloaded_File allows you to keep the file downloaded after its played, so that the next time you run the script with the same URL, the script will see its already downloaded.
    • This can help reduce unnecessary repeat downloads.
    • If you want the script to delete the file after its downloaded and played, just set Keep_Downloaded_Files to 0.
If you have any issues or further feature requests, let me know!

Download: EZT-AudioPlayer.json

EZT-AudioPlayer.json (48.7 KB)

Hello @eztech

Thank you for adding what I wanted in this code and more.

I tried the code as soon as I got to work in the morning.
running smoothly on my own computer;

  • text voiceover.
  • file voiceover.
  • Download and voiceover files from simplefiles.

Those who do not work;
*voice volume adjustment.

  • volume setting for audio playing from file.
  • Downloading files (simplefiles are fine, but it would be more useful to download from google driver and do the same task)

I tried on 2 windows 7 machines;
I didn’t get an access denied error. The code said successful, but the audio, playback and download features did not work. It did not generate the log file.

I am forwarding my related log file and panel logs via DM.

I wish you good work.
Kind regards,