From cfcd7d7588bf4d4cbb6aecc13e2c1e6e13a7bd76 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 30 May 2021 22:36:52 +0200 Subject: [PATCH] Sound update --- Moose Development/Moose/Globals.lua | 5 ++-- Moose Development/Moose/Ops/ATIS.lua | 4 +-- Moose Development/Moose/Sound/RadioQueue.lua | 30 ++++++++++++++----- Moose Development/Moose/Sound/SRS.lua | 5 +--- Moose Development/Moose/Sound/SoundOutput.lua | 19 ++++++++++-- Moose Development/Moose/Sound/UserSound.lua | 4 +-- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/Moose Development/Moose/Globals.lua b/Moose Development/Moose/Globals.lua index fdc6db2c7..734f7c1df 100644 --- a/Moose Development/Moose/Globals.lua +++ b/Moose Development/Moose/Globals.lua @@ -20,8 +20,7 @@ _DATABASE:_RegisterCargos() _DATABASE:_RegisterZones() --- Check if os etc is available. -BASE:I("Checking de-sanitization of os, io and lfs (Check /Scripts/MissionScripting.lua and commend out sanitizeModule(''). Use at your own risk!)") - +BASE:I("Checking de-sanitization of os, io and lfs:") local __na=false if os then BASE:I("- os available") @@ -42,5 +41,5 @@ else __na=true end if __na then - BASE:I("Check /Scripts/MissionScripting.lua and commend out the lines with sanitizeModule(''). Use at your own risk!)") + BASE:I("Check /Scripts/MissionScripting.lua and comment out the lines with sanitizeModule(''). Use at your own risk!)") end \ No newline at end of file diff --git a/Moose Development/Moose/Ops/ATIS.lua b/Moose Development/Moose/Ops/ATIS.lua index 3870ba197..c278539fc 100644 --- a/Moose Development/Moose/Ops/ATIS.lua +++ b/Moose Development/Moose/Ops/ATIS.lua @@ -1115,6 +1115,7 @@ function ATIS:SetSTTS(PathToSRS, Gender, Culture, Voice, Port) self.msrs:SetGender(Gender) self.msrs:SetCulture(Culture) self.msrs:SetVoice(Voice) + self.msrs:SetPort(Port) return self end @@ -2187,9 +2188,6 @@ function ATIS:onafterReport(From, Event, To, Text) -- Replace ";" by "." local text=string.gsub(text, ";", ". ") env.info("FF: "..text) - - --local msrs=MSRS:New("D:\\DCS\\_SRS\\", 305, Modulation) - --msrs:PlayText(text) -- Play text-to-speech report. self.msrs:PlayText(text) diff --git a/Moose Development/Moose/Sound/RadioQueue.lua b/Moose Development/Moose/Sound/RadioQueue.lua index 53207850f..11cea9de8 100644 --- a/Moose Development/Moose/Sound/RadioQueue.lua +++ b/Moose Development/Moose/Sound/RadioQueue.lua @@ -70,8 +70,8 @@ RADIOQUEUE = { -- @field #boolean isplaying If true, transmission is currently playing. -- @field #number Tplay Mission time (abs) in seconds when the transmission should be played. -- @field #number interval Interval in seconds before next transmission. --- @field Sound.SoundFile#SOUNDFILE soundfile Sound file object to play via SRS. --- @field Sound.SoundFile#SOUNDTEXT soundtext Sound TTS object to play via SRS. +-- @field Sound.SoundOutput#SOUNDFILE soundfile Sound file object to play via SRS. +-- @field Sound.SoundOutput#SOUNDTEXT soundtext Sound TTS object to play via SRS. --- Create a new RADIOQUEUE object for a given radio frequency/modulation. @@ -176,9 +176,11 @@ end --- Set SRS. -- @param #RADIOQUEUE self -- @param #string PathToSRS Path to SRS. +-- @param #number Port SRS port. Default 5002. -- @return #RADIOQUEUE self The RADIOQUEUE object. -function RADIOQUEUE:SetSRS(PathToSRS) +function RADIOQUEUE:SetSRS(PathToSRS, Port) self.msrs=MSRS:New(PathToSRS, self.frequency/1000000, self.modulation) + self.msrs:SetPort(Port) return self end @@ -284,19 +286,33 @@ function RADIOQUEUE:NewTransmission(filename, duration, path, tstart, interval, return transmission end ---- Create a new transmission and add it to the radio queue. +--- Add a SOUNDFILE to the radio queue. -- @param #RADIOQUEUE self -- @param Sound.SoundOutput#SOUNDFILE soundfile Sound file object to be added. -- @param #number tstart Start time (abs) seconds. Default now. -- @param #number interval Interval in seconds after the last transmission finished. -- @return #RADIOQUEUE self function RADIOQUEUE:AddSoundFile(soundfile, tstart, interval) - env.info(string.format("FF add soundfile: name=%s%s", soundfile:GetPath(), soundfile:GetFileName())) + --env.info(string.format("FF add soundfile: name=%s%s", soundfile:GetPath(), soundfile:GetFileName())) local transmission=self:NewTransmission(soundfile:GetFileName(), soundfile.duration, soundfile:GetPath(), tstart, interval, soundfile.subtitle, soundfile.subduration) transmission.soundfile=soundfile return self end +--- Add a SOUNDTEXT to the radio queue. +-- @param #RADIOQUEUE self +-- @param Sound.SoundOutput#SOUNDTEXT soundtext Text-to-speech text. +-- @param #number tstart Start time (abs) seconds. Default now. +-- @param #number interval Interval in seconds after the last transmission finished. +-- @return #RADIOQUEUE self +function RADIOQUEUE:AddSoundText(soundtext, tstart, interval) + + local transmission=self:NewTransmission("SoundText.ogg", soundtext.duration, nil, tstart, interval, soundtext.subtitle, soundtext.subduration) + transmission.soundtext=soundtext + return self +end + + --- Convert a number (as string) into a radio transmission. -- E.g. for board number or headings. -- @param #RADIOQUEUE self @@ -340,7 +356,7 @@ end -- @param #RADIOQUEUE.Transmission transmission The transmission. function RADIOQUEUE:Broadcast(transmission) - if (transmission.soundfile or transmission.soundtext) and self.msrs then + if ((transmission.soundfile and transmission.soundfile.useSRS) or transmission.soundtext) and self.msrs then self:_BroadcastSRS(transmission) return end @@ -441,7 +457,7 @@ end -- @param #RADIOQUEUE.Transmission transmission The transmission. function RADIOQUEUE:_BroadcastSRS(transmission) - if transmission.soundfile then + if transmission.soundfile and transmission.soundfile.useSRS then self.msrs:PlaySoundFile(transmission.soundfile) elseif transmission.soundtext then self.msrs:PlaySoundText(transmission.soundtext) diff --git a/Moose Development/Moose/Sound/SRS.lua b/Moose Development/Moose/Sound/SRS.lua index 78cbaeaf2..119f9b167 100644 --- a/Moose Development/Moose/Sound/SRS.lua +++ b/Moose Development/Moose/Sound/SRS.lua @@ -447,14 +447,11 @@ function MSRS:_GetCommand(freqs, modus, coal, gender, voice, culture, volume, sp speed=speed or self.speed port=port or self.port - env.info("FF gender="..tostring(gender)) - env.info("FF gender="..tostring(self.gender)) - -- This did not work well. Stopped if the transmission was a bit longer with no apparent error. --local command=string.format("%s --freqs=%s --modulations=%s --coalition=%d --port=%d --volume=%.2f --speed=%d", exe, freqs, modus, coal, port, volume, speed) -- Command from orig STTS script. Works better for some unknown reason! - local command=string.format("start /min \"\" /d \"%s\" /b \"%s\" -f %s -m %s -c %s -p %s -n \"%s\"", path, exe, freqs, modus, coal, port, "ROBOT") + local command=string.format("start /min \"\" /d \"%s\" /b \"%s\" -f %s -m %s -c %s -p %s -n \"%s\" -h", path, exe, freqs, modus, coal, port, "ROBOT") -- Set voice or gender/culture. if voice then diff --git a/Moose Development/Moose/Sound/SoundOutput.lua b/Moose Development/Moose/Sound/SoundOutput.lua index 697d63941..bb974af08 100644 --- a/Moose Development/Moose/Sound/SoundOutput.lua +++ b/Moose Development/Moose/Sound/SoundOutput.lua @@ -57,7 +57,7 @@ do -- Sound File -- @field #string duration Duration of the sound file in seconds. -- @field #string subtitle Subtitle of the transmission. -- @field #number subduration Duration in seconds how long the subtitle is displayed. - -- @field #boolean insideMiz If true (default), the sound file is located inside the mission .miz file. + -- @field #boolean useSRS If true, sound file is played via SRS. Sound file needs to be on local disk not inside the miz file! -- @extends Core.Base#BASE @@ -75,7 +75,7 @@ do -- Sound File duration = 3, subtitle = nil, subduration = 0, - insideMiz = true, + useSRS = false, } --- Constructor to create a new SOUNDFILE object. @@ -178,6 +178,19 @@ do -- Sound File return name end + --- Get the complete sound file name inlcuding its path. + -- @param #SOUNDFILE self + -- @param #boolean Switch If true or nil, use SRS. If false, use DCS transmission. + -- @return #SOUNDFILE self + function SOUNDFILE:UseSRS(Switch) + if Switch==true or Switch==nil then + self.useSRS=true + else + self.useSRS=false + end + return self + end + end do -- Text-To-Speech @@ -224,7 +237,7 @@ do -- Text-To-Speech local self=BASE:Inherit(self, BASE:New()) -- #SOUNDTEXT self:SetText(Text) - self:SetDuration(Duration) + self:SetDuration(Duration or STTS.getSpeechTime(Text)) --self:SetGender() --self:SetCulture() diff --git a/Moose Development/Moose/Sound/UserSound.lua b/Moose Development/Moose/Sound/UserSound.lua index b0f6fb393..8b94ad114 100644 --- a/Moose Development/Moose/Sound/UserSound.lua +++ b/Moose Development/Moose/Sound/UserSound.lua @@ -1,4 +1,4 @@ ---- **Core** - Manage user sound. +--- **Sound** - Manage user sound. -- -- === -- @@ -16,7 +16,7 @@ -- -- === -- --- @module Core.UserSound +-- @module Sound.UserSound -- @image Core_Usersound.JPG do -- UserSound