SGT Coyle Posted February 2, 2020 Share Posted February 2, 2020 (edited) Thanks to lxsapper, A quick function that will allow the playing of a wav file with a button/switch action/ int PlaySound() { system("spawn -w "D:\\DCS_Device_Profiles\\Common_Files\\Sound" "D:\\DCS_Device_Profiles\\Common_Files\\Sound\\sWavPlayer.exe a10c.wav""); printf("Sound should play...........\xa"); } Put that in a .tmh file and call it with EXEC("PlaySound();"). Replace sWavPlayer with any command line player, and have it in same folder as .wav to be played. Super simple. Thanks again lxsapper. OP I've been trying to get .wav file to play with using the example in the SE Basics pdf, but there seems to be a lack of detail, or understanding on my part. I have a .wav file, and I down loaded sWavePlyer. I setup the .wav to play on sWavePlayer, but when I try to run it I get nothing. OK, So had no luck getting anything to compile or load, so starting from scratch, this is what I've got to compile and run: Sound_Play_TEST.tmc include "target.tmh" include "Sounds.tmh" //program startup int main() { if(Init(&EventHandle)) return 1; // declare the event handler, return on error EXEC("PlaySound()"); //This should play wav file on script start. } //event handler int EventHandle(int type, alias o, int x) { DefaultMapping(&o, x); //add event handling code here } Sounds.tmh int PlaySound() { system ("spawn -w \"D:\\DCS_Device_Profiles\\Common_Files\" \"D\\DCS_Device_Profiles\\Common_Files\\swavplayer Snd_TEST.wav\""); }The above Compiles and runs without error, but of course no sound plays. This is killing me. Help please. Edited February 9, 2020 by SGT Coyle Was so lost I decided to start over hope that doesn't trigger anyone Night Ops in the Harrier IYAOYAS Link to comment Share on other sites More sharing options...
TheHog107 Posted February 5, 2020 Share Posted February 5, 2020 just a guess but do you need to specify an executable to run the wav file? "wavplayer.exe D:\\DCS_Device_Profiles\\Common_Files\\TARGET_DOWN_Layer.wav""); I have no experience in "Target" however as a software developer it makes sense. Link to comment Share on other sites More sharing options...
SGT Coyle Posted February 6, 2020 Author Share Posted February 6, 2020 Ya, I'm pretty lost at this point. I made a .bat file that ran and plays, but I have no idea how to get TARGET to execute it. Night Ops in the Harrier IYAOYAS Link to comment Share on other sites More sharing options...
lxsapper Posted February 6, 2020 Share Posted February 6, 2020 I think TheHog is right SGT Coyle, you need to call upon the executable to run the wav file, Target as far as I know can only execute executable files, but your code looks like you are trying to call upon the .wav file directly. Link to comment Share on other sites More sharing options...
lxsapper Posted February 6, 2020 Share Posted February 6, 2020 I got it working with this code: system ("spawn -w "e:\\sWavPlayer" "e:\\sWavPlayer\\sWavPlayer.exe untitled.wav""); I cannot get the thing to work on a button press. It will not compile. I can't complile you code for a button press eighter: MapKey(&Throttle,LTB, EXEC("system("spawn -w "D:\\DCS_Device_Profiles\\Common_Files" "D:\\DCS_Device_Profiles\\Common_Files\\TARGET_DOWN_Layer.wav"")")); Link to comment Share on other sites More sharing options...
SGT Coyle Posted February 6, 2020 Author Share Posted February 6, 2020 (edited) OK, So had no luck getting anything to compile or load, so starting from scratch, this is what I've got to compile and run: Sound_Play_TEST.tmc include "target.tmh" include "Sounds.tmh" //program startup int main() { if(Init(&EventHandle)) return 1; // declare the event handler, return on error EXEC("PlaySound()"); //This should play wav file on script start. } //event handler int EventHandle(int type, alias o, int x) { DefaultMapping(&o, x); //add event handling code here } Sounds.tmh int PlaySound() { system ("spawn -w \"D:\\DCS_Device_Profiles\\Common_Files\" \"D\\DCS_Device_Profiles\\Common_Files\\swavplayer Snd_TEST.wav\""); } The above Compiles and runs without error, but of course no sound plays. Edited my OP to start over. Edited February 6, 2020 by SGT Coyle Night Ops in the Harrier IYAOYAS Link to comment Share on other sites More sharing options...
lxsapper Posted February 6, 2020 Share Posted February 6, 2020 If that is the exact code you are using you are missing ":" and a couple""in there: int PlaySound() { system ("spawn -w "D:\\DCS_Device_Profiles\\Common_Files\" "D:\\DCS_Device_Profiles\\Common_Files\\swavplayer Snd_TEST.wav\""); } I got it working, and it's very similar to what you have. Link to comment Share on other sites More sharing options...
lxsapper Posted February 6, 2020 Share Posted February 6, 2020 (edited) This are the relevant parts of what I'm using: include "targetdx128.tmh" include "DCS_XsMacro.ttm" include "_DCS A-10C_128.tmc" int main() { SetShiftButton(&Joystick, S3, &Joystick, H4U, 0, 0); // IO Shift and UMD Setup MapKeyIOUMD(&Throttle, CHF, EXEC("ProfileA10C();"), DX36, DX36, DX36, DX36, DX36); } int ProfileA10C() { system("spawn -w "d:\\TARGET Profiles\\Sounds" "d:\\TARGET Profiles\\Sounds\\sWavPlayer.exe a-10c.wav""); } I had to place the swavplayer.exe in the same folder as my .wav's, I counldn't get it to work any other way. Edited February 6, 2020 by lxsapper Link to comment Share on other sites More sharing options...
SGT Coyle Posted February 6, 2020 Author Share Posted February 6, 2020 I keep getting : Compile Error:Syntax error: d in Sounds.tmh at line 3 I actually cut n paste your code in. Just changed the folder name. Night Ops in the Harrier IYAOYAS Link to comment Share on other sites More sharing options...
lxsapper Posted February 7, 2020 Share Posted February 7, 2020 The forum is deleting backslashes from the copy/pasted code. Probably why yours isn't compiling for me, and mine for you. So here is an image from the code in target: Link to comment Share on other sites More sharing options...
SGT Coyle Posted February 7, 2020 Author Share Posted February 7, 2020 (edited) Got It running. Thanks Lxsapper. Edited February 7, 2020 by SGT Coyle Night Ops in the Harrier IYAOYAS Link to comment Share on other sites More sharing options...
Drakoz Posted February 10, 2020 Share Posted February 10, 2020 I was messing around more with playing .WAV files and thought the following would be useful. A function call to make it easier to play .WAV files. The following examples are complete .tmc files which you should be able to copy and paste into the TARGET editor. There should be no copy and paste issues related to the forums cutting out characters as mentioned in previous posts. There are two versions. Both are intended that you store all your .WAV files in a single folder (e.g. a Sounds folder in your Scripts folder). The first example expects that sWavPlayer.exe is in the same folder as the .WAV files. The second example allows for sWavPlayer.exe to be in a different folder than the .WAV files (e.g. c:\bin\sWavPlayer.exe). It was mentioned before this 2nd example didn't work because sWavPlayer.exe expects the .WAV file to be in the same folder. But sWavPlayer.exe works with files in a different folder if you give it a full path to the .WAV file. Below shows how to do it in TARGET. The main difference is, the first one uses "spawn -w" to set the working folder for sWavPlayer.exe, but then sWavPlayer expects the .WAV files to be in the same folder. The second example just uses "spawn" with no -w option and uses full path names to both sWavPlayer.exe and the folder where you store your .WAV files. You could do the file paths many ways. I provided two examples to help everyone understand how to build a system("spawn"); command using variables and defines to configure full paths. The trick is to use sprintf() to concatenate the strings together in to buffer. Don't forget to set SOUNDS_Folder and sWavPlayer_Folder to match the path to your .WAV files or where you store sWavPlayer, as well as change the name of the .WAV file used (I am playing a file called failure_beep.wav. First Example: sWavPlayer.exe and .WAV files in same folder include "target.tmh" int main() { if(Init(&EventHandle)) return 1; // declare the event handler, return on error MapKey(&Throttle, LDGH, EXEC("PlayWav(\"failure_beep.wav\");")); } //****************************************************************** // PlayWav() // Function to play a .WAV file using sWavPlayer.exe // sWavPlayer.exe can be downloaded from here: http://www.dcmembers.com/skwire/download/swavplayer/ // // Set SOUNDS_Folder = the folder where you store sounds. Make sure sWavPlayer.exe is also stored in this folder. // Make sure to use \\ for all occurrences of \ in the path. define SOUNDS_Folder "C:\\Users\\mike\\AppData\\Roaming\\Thrustmaster\\TARGET\\Scripts\\Sounds\\" int PlayWav(alias wavfile) { if (&wavfile == "") return 0; // exit if no parameter given printf("PlayWav playing file: %s\xa", &wavfile); alias f = SOUNDS_Folder; char buffer; Dim(&buffer, 256); // max command length is 256 characters sprintf(&buffer, "spawn -w %s %ssWavPlayer.exe %s", &f, &f, &wavfile); printf("buffer = %s\xa", &buffer); system(&buffer); } //event handler int EventHandle(int type, alias o, int x) { DefaultMapping(&o, x); } Second Example: Separate paths for sWavPlayer.exe and the .WAV files. include "target.tmh" int main() { if(Init(&EventHandle)) return 1; // declare the event handler, return on error MapKey(&Throttle, LDGH, EXEC("PlayWav(\"failure_beep.wav\");")); } //****************************************************************** // PlayWav() // Function to play a .WAV file using sWavPlayer.exe // sWavPlayer.exe can be downloaded from here: http://www.dcmembers.com/skwire/download/swavplayer/ // // Set SOUNDS_Folder = the folder where you store sounds. Make sure sWavPlayer.exe is also stored in this folder. // Make sure to use \\ for all occurrences of \ in the path. define SOUNDS_Folder "C:\\Users\\mike\\AppData\\Roaming\\Thrustmaster\\TARGET\\Scripts\\Sounds\\" // Set sWavPlayer_Folder = the folder that contains sWavPlayer.exe define sWavPlayer_Folder "c:\\bin\\" int PlayWav(alias wavfile) { if (&wavfile == "") return 0; // exit if no parameter given printf("PlayWav playing file: %s\xa", &wavfile); alias f1 = SOUNDS_Folder; alias f2 = sWavPlayer_Folder; char buffer; Dim(&buffer, 256); // max command length is 256 characters sprintf(&buffer, "spawn %ssWavPlayer.exe %s%s", &f2, &f1, &wavfile); printf("buffer = %s\xa", &buffer); system(&buffer); } //event handler int EventHandle(int type, alias o, int x) { DefaultMapping(&o, x); } Link to comment Share on other sites More sharing options...
Drakoz Posted February 10, 2020 Share Posted February 10, 2020 And if you want a way to do Text to Speech in TARGET, the following uses Windows mshta.exe to execute some vbscript to speak the given text. Paste in TARGET and run it to try it out. Don't forget when using this in an EXEC(), you must use \" (a backslash before the quote) in order to escape the quotes and properly pass them to Speak(). See usage examples below. include "target.tmh" // Disable Speak() output - disabled =0, enabled =1 define SpeakEnabled 1 int main() { if(Init(&EventHandle)) return 1; // declare the event handler, return on error Speak("Script Loaded"); Speak("Press LDGH to say more"); MapKey(&Throttle, LDGH, EXEC("Speak(\"Hello World\");")); } //****************************************************************** // Speak() // Text to Speech - this function uses Windows mshta.exe and a simple Visual Basic script to perform text to speech // text - the text or phrase to speak // The concept of using mshta vbscript was found here: https://stackoverflow.com/questions/1040655/ms-speech-from-command-line // No extra programs are required for this to work. int Speak(alias text) { if (!SpeakEnabled) return 0; // disable TextToSpeech sounds if (&text == "") return 0; // exit if no parameter given //printf("Speaking: %s\xa", &text); char buffer; Dim(&buffer, 256); sprintf(&buffer, "spawn mshta vbscript:Execute(\"CreateObject(\"\"SAPI.SpVoice\"\").Speak(\"\"%s\"\")(window.close)\")", &text); system(&buffer); } //event handler int EventHandle(int type, alias o, int x) { DefaultMapping(&o, x); } Link to comment Share on other sites More sharing options...
SGT Coyle Posted February 10, 2020 Author Share Posted February 10, 2020 Awesome! I'll be trying that toot sweet. Night Ops in the Harrier IYAOYAS Link to comment Share on other sites More sharing options...
lxsapper Posted February 10, 2020 Share Posted February 10, 2020 Thanks for this Drakoz. And as a sidenote I didn't say swavplayer couldn't play files in a diferent directory. I didn't know how to do it with Target, because putting the path down was giving me syntax error. Thank you for solving it! Link to comment Share on other sites More sharing options...
Drakoz Posted February 10, 2020 Share Posted February 10, 2020 Thanks for this Drakoz. And as a sidenote I didn't say swavplayer couldn't play files in a diferent directory. I didn't know how to do it with Target, because putting the path down was giving me syntax error. Thank you for solving it! Yes, that is what I thought. Hence why I posted two examples, each of which deal with the paths differently. Figuring out how to manipulate strings and alias's is kind of confusing in TARGET because TARGET doesn't handle strings quite the same as normal C. Link to comment Share on other sites More sharing options...
Recommended Posts