* Fixes for alternative backend
This commit is contained in:
Applevangelist 2023-10-13 16:13:12 +02:00
parent b9cc66004d
commit 2ebad9ce96

View File

@ -46,6 +46,7 @@
-- @field #string path Path to the SRS exe. This includes the final slash "/". -- @field #string path Path to the SRS exe. This includes the final slash "/".
-- @field #string google Full path google credentials JSON file, e.g. "C:\Users\username\Downloads\service-account-file.json". -- @field #string google Full path google credentials JSON file, e.g. "C:\Users\username\Downloads\service-account-file.json".
-- @field #string Label Label showing up on the SRS radio overlay. Default is "ROBOT". No spaces allowed. -- @field #string Label Label showing up on the SRS radio overlay. Default is "ROBOT". No spaces allowed.
-- @field #table AltBackend Table containing functions and variables to enable an alternate backend to transmit to SRS.
-- @extends Core.Base#BASE -- @extends Core.Base#BASE
--- *It is a very sad thing that nowadays there is so little useless information.* - Oscar Wilde --- *It is a very sad thing that nowadays there is so little useless information.* - Oscar Wilde
@ -123,6 +124,50 @@
-- --
-- Use @{#MSRS.SetVolume} to define the SRS volume. Defaults to 1.0. Allowed values are between 0.0 and 1.0, from silent to loudest. -- Use @{#MSRS.SetVolume} to define the SRS volume. Defaults to 1.0. Allowed values are between 0.0 and 1.0, from silent to loudest.
-- --
-- ## Set DCS-gRPC as an alternative to 'DCS-SR-ExternalAudio.exe' for TTS
--
-- Use @{#MSRS.SetDefaultBackendGRPC} to enable [DCS-gRPC](https://github.com/DCS-gRPC/rust-server) as an alternate backend for transmitting text-to-speech over SRS.
-- This can be useful if 'DCS-SR-ExternalAudio.exe' cannot be used in the environment, or to use Azure or AWS clouds for TTS. Note that DCS-gRPC does not (yet?) support
-- all of the features and options available with 'DCS-SR-ExternalAudio.exe'. Of note, only text-to-speech is supported and it it cannot be used to transmit audio files.
--
-- DCS-gRPC must be installed and configured per the [DCS-gRPC documentation](https://github.com/DCS-gRPC/rust-server) and already running via either the 'autostart' mechanism
-- or a Lua call to 'GRPC.load()' prior to use of the alternate DCS-gRPC backend. If a cloud TTS provider is being used, the API key must be set via the 'Config\dcs-grpc.lua'
-- configuration file prior DCS-gRPC being started. DCS-gRPC can be used both with DCS dedicated server and regular DCS installations.
--
-- To use the default local Windows TTS with DCS-gRPC, Windows 2019 Server (or newer) or Windows 10/11 are required. Voices for non-local languages and dialects may need to
-- be explicitly installed.
--
-- To set the MSRS class to use the DCS-gRPC backend for all future instances, call the function `MSRS.SetDefaultBackendGRPC()`.
--
-- **Note** - When using other classes that use MSRS with the alternate DCS-gRPC backend, pass them strings instead of nil values for non-applicable fields with filesystem paths,
-- such as the SRS path or Google credential path. This will help maximize compatibility with other classes that were written for the default backend.
--
-- Basic Play Text-To-Speech example using alternate DCS-gRPC backend (DCS-gRPC not previously started):
--
-- -- Start DCS-gRPC
-- GRPC.load()
-- -- Select the alternate DCS-gRPC backend for new MSRS instances
-- MSRS.SetDefaultBackendGRPC()
-- -- Create a SOUNDTEXT object.
-- local text=SOUNDTEXT:New("All Enemies destroyed")
-- -- MOOSE SRS
-- local msrs=MSRS:New('', 305.0)
-- -- Text-to speech with default voice after 30 seconds.
-- msrs:PlaySoundText(text, 30)
--
-- Basic example of using another class (ATIS) with SRS and the DCS-gRPC backend (DCS-gRPC not previously started):
--
-- -- Start DCS-gRPC
-- GRPC.load()
-- -- Select the alternate DCS-gRPC backend for new MSRS instances
-- MSRS.SetDefaultBackendGRPC()
-- -- Create new ATIS as usual
-- atis=ATIS:New("Nellis", 251, radio.modulation.AM)
-- -- ATIS:SetSRS() expects a string for the SRS path even though it is not needed with DCS-gRPC
-- atis:SetSRS('')
-- -- Start ATIS
-- atis:Start()
--
-- @field #MSRS -- @field #MSRS
MSRS = { MSRS = {
ClassName = "MSRS", ClassName = "MSRS",
@ -139,11 +184,12 @@ MSRS = {
speed = 1, speed = 1,
coordinate = nil, coordinate = nil,
Label = "ROBOT", Label = "ROBOT",
AltBackend = nil,
} }
--- MSRS class version. --- MSRS class version.
-- @field #string version -- @field #string version
MSRS.version="0.1.1" MSRS.version="0.1.3"
--- Voices --- Voices
-- @type MSRS.Voices -- @type MSRS.Voices
@ -264,16 +310,35 @@ MSRS.Voices = {
-- @param #number Frequency Radio frequency in MHz. Default 143.00 MHz. Can also be given as a #table of multiple frequencies. -- @param #number Frequency Radio frequency in MHz. Default 143.00 MHz. Can also be given as a #table of multiple frequencies.
-- @param #number Modulation Radio modulation: 0=AM (default), 1=FM. See `radio.modulation.AM` and `radio.modulation.FM` enumerators. Can also be given as a #table of multiple modulations. -- @param #number Modulation Radio modulation: 0=AM (default), 1=FM. See `radio.modulation.AM` and `radio.modulation.FM` enumerators. Can also be given as a #table of multiple modulations.
-- @param #number Volume Volume - 1.0 is max, 0.0 is silence -- @param #number Volume Volume - 1.0 is max, 0.0 is silence
-- @param #table AltBackend Optional table containing tables 'Functions' and 'Vars' which add/replace functions and variables for the MSRS instance to allow alternate backends for transmitting to SRS.
-- @return #MSRS self -- @return #MSRS self
function MSRS:New(PathToSRS, Frequency, Modulation, Volume) function MSRS:New(PathToSRS, Frequency, Modulation, Volume, AltBackend)
-- Defaults. -- Defaults.
Frequency =Frequency or 143 Frequency = Frequency or 143
Modulation= Modulation or radio.modulation.AM Modulation = Modulation or radio.modulation.AM
-- Inherit everything from FSM class. -- Inherit everything from FSM class.
local self=BASE:Inherit(self, BASE:New()) -- #MSRS local self=BASE:Inherit(self, BASE:New()) -- #MSRS
-- If AltBackend is supplied, initialize it, which will add/replace functions and variables in this MSRS instance.
if type( AltBackend ) == "table" or type( self.AltBackend ) == "table" then
local Backend = UTILS.DeepCopy(AltBackend) or UTILS.DeepCopy(self.AltBackend)
-- Add parameters to vars so alternate backends can use them if applicable
Backend.Vars = Backend.Vars or {}
Backend.Vars.PathToSRS = UTILS.DeepCopy(PathToSRS) -- DeepCopy probably unecessary
Backend.Vars.Frequency = UTILS.DeepCopy(Frequency)
Backend.Vars.Modulation = UTILS.DeepCopy(Modulation)
Backend.Vars.Volume = UTILS.DeepCopy(Volume) -- DeepCopy probably unecessary
Backend.Functions = Backend.Functions or {}
return self:_NewAltBackend(Backend)
end
-- If no AltBackend table, the proceed with default initialization
self:SetPath(PathToSRS) self:SetPath(PathToSRS)
self:SetPort() self:SetPort()
self:SetFrequencies(Frequency) self:SetFrequencies(Frequency)
@ -517,6 +582,17 @@ function MSRS:SetVoice(Voice)
return self return self
end end
--- Set to use a specific voice. Will override gender and culture settings.
-- @param #MSRS self
-- @param #string Voice Voice.
-- @return #MSRS self
function MSRS:SetDefaultVoice(Voice)
self.defaultVoice=Voice
return self
end
--- Set the coordinate from which the transmissions will be broadcasted. --- Set the coordinate from which the transmissions will be broadcasted.
-- @param #MSRS self -- @param #MSRS self
-- @param Core.Point#COORDINATE Coordinate Origin of the transmission. -- @param Core.Point#COORDINATE Coordinate Origin of the transmission.
@ -530,11 +606,25 @@ end
--- Use google text-to-speech. --- Use google text-to-speech.
-- @param #MSRS self -- @param #MSRS self
-- @param PathToCredentials Full path to the google credentials JSON file, e.g. "C:\Users\username\Downloads\service-account-file.json". -- @param #string PathToCredentials Full path to the google credentials JSON file, e.g. "C:\Users\username\Downloads\service-account-file.json".
-- @return #MSRS self -- @return #MSRS self
function MSRS:SetGoogle(PathToCredentials) function MSRS:SetGoogle(PathToCredentials)
self.google=PathToCredentials self.google=PathToCredentials
self.APIKey=PathToCredentials
self.provider = "gcloud"
return self
end
--- Use google text-to-speech.
-- @param #MSRS self
-- @param #string APIKey API Key, usually a string of length 40 with characters and numbers.
-- @return #MSRS self
function MSRS:SetGoogleAPIKey(APIKey)
self.APIKey=APIKey
self.provider = "gcloud"
return self return self
end end
@ -568,6 +658,32 @@ function MSRS:Help()
return self return self
end end
--- Sets an alternate SRS backend to be used by MSRS to transmit over SRS for all new MSRS class instances.
-- @param #table Backend A table containing a table `Functions` with new/replacement class functions and `Vars` with new/replacement variables.
-- @return #boolean Returns 'true' on success.
function MSRS.SetDefaultBackend(Backend)
if type(Backend) == "table" then
MSRS.AltBackend = UTILS.DeepCopy(Backend)
else
return false
end
return true
end
--- Restores default SRS backend (DCS-SR-ExternalAudio.exe) to be used by all new MSRS class instances to transmit over SRS.
-- @return #boolean Returns 'true' on success.
function MSRS.ResetDefaultBackend()
MSRS.AltBackend = nil
return true
end
--- Sets DCS-gRPC as the default SRS backend for all new MSRS class instances.
-- @return #boolean Returns 'true' on success.
function MSRS.SetDefaultBackendGRPC()
return MSRS.SetDefaultBackend(MSRS_BACKEND_DCSGRPC)
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Transmission Functions -- Transmission Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -736,12 +852,41 @@ end
-- Misc Functions -- Misc Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Adds or replaces functions and variables in the current MSRS class instance to enable an alternate backends for transmitting to SRS.
-- @param #MSRS self
-- @param #table A table containing a table `Functions` with new/replacement class functions and `Vars` with new/replacement variables.
-- @return #MSRS self
function MSRS:_NewAltBackend(Backend)
BASE:T('Entering MSRS:_NewAltBackend()')
-- Add/replace class instance functions with those defined in the alternate backend in Functions table
for funcName,funcDef in pairs(Backend.Functions) do
if type(funcDef) == 'function' then
BASE:T('MSRS (re-)defining function MSRS:' .. funcName )
self[funcName] = funcDef
end
end
-- Add/replace class instance variables with those defined in the alternate backend in Vars table
for varName,varVal in pairs(Backend.Vars) do
BASE:T('MSRS setting self.' .. varName)
self[varName] = UTILS.DeepCopy(varVal)
end
-- If _MSRSbackendInit() is defined in the backend, then run it (it should return self)
if self._MSRSbackendInit and type(self._MSRSbackendInit) == 'function' then
return self:_MSRSbackendInit()
end
return self
end
--- Execute SRS command to play sound using the `DCS-SR-ExternalAudio.exe`. --- Execute SRS command to play sound using the `DCS-SR-ExternalAudio.exe`.
-- @param #MSRS self -- @param #MSRS self
-- @param #string command Command to executer -- @param #string command Command to executer
-- @return #number Return value of os.execute() command. -- @return #number Return value of os.execute() command.
function MSRS:_ExecCommand(command) function MSRS:_ExecCommand(command)
self:T("SRS TTS command="..command)
-- Create a tmp file. -- Create a tmp file.
local filename=os.getenv('TMP').."\\MSRS-"..STTS.uuid()..".bat" local filename=os.getenv('TMP').."\\MSRS-"..STTS.uuid()..".bat"
@ -780,6 +925,23 @@ function MSRS:_ExecCommand(command)
timer.scheduleFunction(os.remove, filename, timer.getTime()+1) timer.scheduleFunction(os.remove, filename, timer.getTime()+1)
timer.scheduleFunction(os.remove, filenvbs, timer.getTime()+1) timer.scheduleFunction(os.remove, filenvbs, timer.getTime()+1)
elseif false then
-- Create a tmp file.
local filenvbs = os.getenv('TMP') .. "\\MSRS-"..STTS.uuid()..".vbs"
-- VBS script
local script = io.open(filenvbs, "w+")
script:write(string.format('Set oShell = CreateObject ("Wscript.Shell")\n'))
script:write(string.format('Dim strArgs\n'))
script:write(string.format('strArgs = "cmd /c %s"\n', filename))
script:write(string.format('oShell.Run strArgs, 0, false'))
script:close()
local runvbs=string.format('cscript.exe //Nologo //B "%s"', filenvbs)
-- Play file in 0.01 seconds
res=os.execute(runvbs)
else else
@ -879,6 +1041,336 @@ function MSRS:_GetCommand(freqs, modus, coal, gender, voice, culture, volume, sp
return command return command
end end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- MSRS DCS-gRPC alternate backend
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Alternate backend for MSRS to enable text-to-speech via DCS-gRPC.
-- ### Author: **dogjutsu**
-- A table containing functions and variables for MSRS to use DCS-gRPC [DCS-gRPC](https://github.com/DCS-gRPC/rust-server) 0.7.0 or newer as a backend to transmit over SRS.
-- This is not a standalone class. Instead, variables and functions under the `Vars` and `Functions` tables get added to or replace MSRS variables/functions when activated.
--
-- @type MSRS_BACKEND_DCSGRPC
-- @field #number version Version number of this alternate backend.
-- @field #table Functions A table of functions that will add or replace the default MSRS class functions.
-- @field #table Vars A table of variables that will add or replace the default MSRS class variables.
MSRS_BACKEND_DCSGRPC = {}
MSRS_BACKEND_DCSGRPC.version = 0.1
MSRS_BACKEND_DCSGRPC.Functions = {}
MSRS_BACKEND_DCSGRPC.Vars = { provider = 'win' }
--- Called by @{#MSRS._NewAltBackend} (if present) immediately after an alternate backend functions and variables for MSRS are added/replaced.
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions._MSRSbackendInit = function (self)
BASE:I('Loaded MSRS DCS-gRPC alternate backend version ' .. self.AltBackend.version or 'unspecified')
return self
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- MSRS DCS-gRPC alternate backend User Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- No-op replacement function for @{#MSRS.SetPath} (Not Applicable)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetPath = function (self)
return self
end
--- No-op replacement function for @{#MSRS.GetPath} (Not Applicable)
-- @param #MSRS self
-- @return #string Empty string
MSRS_BACKEND_DCSGRPC.Functions.GetPath = function (self)
return ''
end
--- No-op replacement function for @{#MSRS.SetVolume} (Not Applicable)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetVolume = function (self)
BASE:I('NOTE: MSRS:SetVolume() not used with DCS-gRPC backend.')
return self
end
--- No-op replacement function for @{#MSRS.GetVolume} (Not Applicable)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.GetVolume = function (self)
BASE:I('NOTE: MSRS:GetVolume() not used with DCS-gRPC backend.')
return 1
end
--- No-op replacement function for @{#MSRS.SetGender} (Not Applicable)
-- @param #MSRS self
-- #string Gender Gender: "male" or "female"
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetGender = function (self, Gender)
-- Use DCS-gRPC default if not specified
if Gender then
self.gender=Gender:lower()
end
-- Debug output.
self:T("Setting gender to "..tostring(self.gender))
return self
end
--- Replacement function for @{#MSRS.SetGoogle} to use google text-to-speech. (API key set as part of DCS-gRPC configuration)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetGoogle = function (self)
self.provider = 'gcloud'
return self
end
--- Replacement function for @{#MSRS.SetGoogle} to use google text-to-speech - here: Set the API key
-- @param #MSRS self
-- @param #string key
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetAPIKey = function (self, key)
self.APIKey = key
return self
end
--- Replacement function for @{#MSRS.SetGoogle} to use google text-to-speech - here: Set the API key
-- @param #MSRS self
-- @param #string voice
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetDefaultVoice = function (self, voice)
self.defaultVoice = voice
return self
end
--- MSRS:SetAWS() Use AWS text-to-speech. (API key set as part of DCS-gRPC configuration)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetAWS = function (self)
self.provider = 'aws'
return self
end
--- MSRS:SetAzure() Use Azure text-to-speech. (API key set as part of DCS-gRPC configuration)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetAzure = function (self)
self.provider = 'azure'
return self
end
--- MSRS:SetWin() Use local Windows OS text-to-speech (Windows Server 2019 / Windows 11 / Windows 10? or newer). (Default)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.SetWin = function (self)
self.provider = 'win'
return self
end
--- Replacement function for @{#MSRS.Help} to display help.
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.Help = function (self)
env.info('For DCS-gRPC help, please see: https://github.com/DCS-gRPC/rust-server')
return self
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- MSRS DCS-gRPC alternate backend Transmission Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- No-op replacement function for @{#MSRS.PlaySoundFile} (Not Applicable)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.PlaySoundFile = function (self)
BASE:E("ERROR: MSRS:PlaySoundFile() is not supported by the DCS-gRPC backend.")
return self
end
--- Replacement function for @{#MSRS.PlaySoundText}
-- @param #MSRS self
-- @param Sound.SoundFile#SOUNDTEXT SoundText Sound text.
-- @param #number Delay Delay in seconds, before the sound file is played.
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.PlaySoundText = function (self, SoundText, Delay)
if Delay and Delay>0 then
self:ScheduleOnce(Delay, self.PlaySoundText, self, SoundText, 0)
else
self:_DCSgRPCtts(tostring(SoundText.text))
end
return self
end
--- Replacement function for @{#MSRS.PlayText}
-- @param #MSRS self
-- @param #string Text Text message.
-- @param #number Delay Delay in seconds, before the message is played.
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.PlayText = function (self, Text, Delay)
if Delay and Delay>0 then
self:ScheduleOnce(Delay, self.PlayText, self, Text, 0)
else
self:_DCSgRPCtts(tostring(Text))
end
return self
end
--- Replacement function for @{#MSRS.PlayText}
-- @param #MSRS self
-- @param #string Text Text message.
-- @param #number Delay Delay in seconds, before the message is played.
-- @param #table Frequencies Radio frequencies.
-- @param #table Modulations Radio modulations. (Non-functional, DCS-gRPC sets automatically)
-- @param #string Gender Gender. (Non-functional, only 'Voice' supported)
-- @param #string Culture Culture. (Non-functional, only 'Voice' supported)
-- @param #string Voice Voice.
-- @param #number Volume Volume. (Non-functional, all transmissions full volume with DCS-gRPC)
-- @param #string Label Label.
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.PlayTextExt = function (self, Text, Delay, Frequencies, Modulations, Gender, Culture, Voice, Volume, Label)
if Delay and Delay>0 then
self:ScheduleOnce(Delay, self.PlayTextExt, self, Text, 0, Frequencies, Modulations, Gender, Culture, Voice, Volume, Label)
else
self:_DCSgRPCtts(tostring(Text), nil, Frequencies, Voice, Label)
end
return self
end
--- No-op replacement function for @{#MSRS.PlayTextFile} (Not Applicable)
-- @param #MSRS self
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions.PlayTextFile = function (self, TextFile, Delay)
BASE:E("ERROR: MSRS:PlayTextFile() is not supported by the DCS-gRPC backend.")
return self
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- MSRS DCS-gRPC alternate backend Misc Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- DCS-gRPC v0.70 TTS API call:
-- GRPC.tts(ssml, frequency[, options]) - Synthesize text (ssml; SSML tags supported) to speech and transmit it over SRS on the frequency with the following optional options (and their defaults):
-- {
-- -- The plain text without any transformations made to it for the purpose of getting it spoken out
-- -- as desired (no SSML tags, no FOUR NINER instead of 49, ...). Even though this field is
-- -- optional, please consider providing it as it can be used to display the spoken text to players
-- -- with hearing impairments.
-- plaintext = null, -- e.g. `= "Hello Pilot"`
-- -- Name of the SRS client.
-- srsClientName = "DCS-gRPC",
-- -- The origin of the transmission. Relevant if the SRS server has "Line of
-- -- Sight" and/or "Distance Limit" enabled.
-- position = {
-- lat = 0.0,
-- lon = 0.0,
-- alt = 0.0, -- in meters
-- },
-- -- The coalition of the transmission. Relevant if the SRS server has "Secure
-- -- Coalition Radios" enabled. Supported values are: `blue` and `red`. Defaults
-- -- to being spectator if not specified.
-- coalition = null,
-- -- TTS provider to be use. Defaults to the one configured in your config or to Windows'
-- -- built-in TTS. Examples:
-- -- `= { aws = {} }` / `= { aws = { voice = "..." } }` enable AWS TTS
-- -- `= { azure = {} }` / `= { azure = { voice = "..." } }` enable Azure TTS
-- -- `= { gcloud = {} }` / `= { gcloud = { voice = "..." } }` enable Google Cloud TTS
-- -- `= { win = {} }` / `= { win = { voice = "..." } }` enable Windows TTS
-- provider = null,
-- }
--- Make DCS-gRPC API call to transmit text-to-speech over SRS.
-- @param #MSRS self
-- @param #string Text Text of message to transmit (can also be SSML).
-- @param #string Optional plaintext version of message (for accessiblity)
-- @param #table Frequencies Radio frequencies to transmit on. Can also accept a number in MHz.
-- @param #string Voice Voice for the TTS provider to user.
-- @param #string Label Label (SRS diplays as name of the transmitter).
-- @return #MSRS self
MSRS_BACKEND_DCSGRPC.Functions._DCSgRPCtts = function (self, Text, Plaintext, Frequencies, Voice, Label)
BASE:T("MSRS_BACKEND_DCSGRPC:_DCSgRPCtts()")
BASE:T({Text, Plaintext, Frequencies, Voice, Label})
local options = {}
local ssml = Text or ''
local XmitFrequencies = Frequencies or self.Frequency
if type(XmitFrequencies)~="table" then
XmitFrequencies={XmitFrequencies}
end
options.plaintext = Plaintext
options.srsClientName = Label or self.Label
options.position = {}
if self.coordinate then
options.position.lat, options.position.lat, options.position.alt = self:_GetLatLongAlt(self.coordinate)
end
options.position.lat = options.position.lat or 0.0
options.position.lon = options.position.lon or 0.0
options.position.alt = options.position.alt or 0.0
if UTILS.GetCoalitionName(self.coalition) == 'Blue' then
options.coalition = 'blue'
elseif UTILS.GetCoalitionName(self.coalition) == 'Red' then
options.coalition = 'red'
end
options[self.provider] = {}
if self.APIKey then
options[self.provider].key = self.APIKey
end
if self.defaultVoice then
options[self.provider].voice = self.defaultVoice
end
if self.voice then
options[self.provider].voice = Voice or self.voice
elseif ssml then
-- DCS-gRPC doesn't directly support language/gender, but can use SSML
-- Only use if a voice isn't explicitly set
local preTag, genderProp, langProp, postTag = '', '', '', ''
if self.gender then
genderProp = ' gender=\"' .. self.gender .. '\"'
end
if self.culture then
langProp = ' language=\"' .. self.culture .. '\"'
end
if self.culture or self.gender then
preTag = '<voice' .. langProp .. genderProp .. '>'
postTag = '</voice>'
ssml = preTag .. Text .. postTag
end
end
for _,_freq in ipairs(XmitFrequencies) do
local freq = _freq*1000000
BASE:T("GRPC.tts")
BASE:T(ssml)
BASE:T(freq)
BASE:T(options)
GRPC.tts(ssml, freq, options)
end
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Manages radio transmissions. --- Manages radio transmissions.
@ -922,6 +1414,11 @@ MSRSQUEUE = {
-- @field #number interval Interval in seconds before next transmission. -- @field #number interval Interval in seconds before next transmission.
-- @field #boolean TransmitOnlyWithPlayers If true, only transmit if there are alive Players. -- @field #boolean TransmitOnlyWithPlayers If true, only transmit if there are alive Players.
-- @field Core.Set#SET_CLIENT PlayerSet PlayerSet created when TransmitOnlyWithPlayers == true -- @field Core.Set#SET_CLIENT PlayerSet PlayerSet created when TransmitOnlyWithPlayers == true
-- @field #string gender Voice gender
-- @field #string culture Voice culture
-- @field #string voice Voice if any
-- @field #number volume Volume
-- @field #string label Label to be used
--- Create a new MSRSQUEUE object for a given radio frequency/modulation. --- Create a new MSRSQUEUE object for a given radio frequency/modulation.
-- @param #MSRSQUEUE self -- @param #MSRSQUEUE self
@ -1001,8 +1498,13 @@ end
-- @param #number subduration Duration [sec] of the subtitle being displayed. Default 5 sec. -- @param #number subduration Duration [sec] of the subtitle being displayed. Default 5 sec.
-- @param #number frequency Radio frequency if other than MSRS default. -- @param #number frequency Radio frequency if other than MSRS default.
-- @param #number modulation Radio modulation if other then MSRS default. -- @param #number modulation Radio modulation if other then MSRS default.
-- @param #string gender Gender of the voice
-- @param #string culture Culture of the voice
-- @param #string voice Specific voice
-- @param #number volume Volume setting
-- @param #string label Label to be used
-- @return #MSRSQUEUE.Transmission Radio transmission table. -- @return #MSRSQUEUE.Transmission Radio transmission table.
function MSRSQUEUE:NewTransmission(text, duration, msrs, tstart, interval, subgroups, subtitle, subduration, frequency, modulation) function MSRSQUEUE:NewTransmission(text, duration, msrs, tstart, interval, subgroups, subtitle, subduration, frequency, modulation, gender, culture, voice, volume, label)
if self.TransmitOnlyWithPlayers then if self.TransmitOnlyWithPlayers then
if self.PlayerSet and self.PlayerSet:CountAlive() == 0 then if self.PlayerSet and self.PlayerSet:CountAlive() == 0 then
@ -1037,6 +1539,11 @@ function MSRSQUEUE:NewTransmission(text, duration, msrs, tstart, interval, subgr
else else
transmission.subduration=0 --nil transmission.subduration=0 --nil
end end
transmission.gender = gender
transmission.culture = culture
transmission.voice = voice
transmission.gender = volume
transmission.label = label
-- Add transmission to queue. -- Add transmission to queue.
self:AddTransmission(transmission) self:AddTransmission(transmission)
@ -1050,7 +1557,7 @@ end
function MSRSQUEUE:Broadcast(transmission) function MSRSQUEUE:Broadcast(transmission)
if transmission.frequency then if transmission.frequency then
transmission.msrs:PlayTextExt(transmission.text, nil, transmission.frequency, transmission.modulation, Gender, Culture, Voice, Volume, Label) transmission.msrs:PlayTextExt(transmission.text, nil, transmission.frequency, transmission.modulation, transmission.gender, transmission.culture, transmission.voice, transmission.volume, transmission.label)
else else
transmission.msrs:PlayText(transmission.text) transmission.msrs:PlayText(transmission.text)
end end