Executing Command Line from With XSL (Using Java)
Posted: Wed May 12, 2021 12:10 pm
As one step of a larger workflow, I have a portion of text from an XML document that I would like to be converting to an audio file. I can do this in multiple steps, having the XSL write the text to a text file, and then use the command line on my Mac to run the 'say' command and convert the text file to an audio file using the built in text to speech functionality. Since I'll be doing this a lot, I'm hoping to streamline the process by having the command line instruction run from directly within XSL, if possible.
After finding this information, I was able to get the access of the command line to work, but can't seem to get it to save files. I have stored the text I want converted to audio into an XSL variable, $text. By declaring a namespace in my root stylesheet element
and using this
my computer will actually speak the text aloud, thus proving that access to the command line works. But when I try to add options to the 'say' command to have the audio saved to a file instead of spoken aloud, like this:
absolutely nothing happens. No file is created (I've searched the Mac and can't find it anywhere) I know the command is correct, since a straight copy and paste to the command line in Terminal will get the desired resulting file (when I substitute a string for the variable). So executing that exact command from the command line works, but from within the Java code inside XSL in Oxygen, it doesn't work.
My only thought is that from the command line, it knows where to put a file, in the "current working directory". I'm guessing that when executed within the Java environment as I am doing it within Oxygen, there is no definable "current working directory". Or at least not in a way that can be usable. Thus, it can't actually create the file anywhere. Can anyone comment on that?
Any insight into what might be going on here, how Oxygen, Java, and XSL are working together here, would be greatly appreciated!
After finding this information, I was able to get the access of the command line to work, but can't seem to get it to save files. I have stored the text I want converted to audio into an XSL variable, $text. By declaring a namespace in my root stylesheet element
Code: Select all
xmlns:jv="java:java.lang.Runtime"
Code: Select all
<xsl:value-of select="jv:exec(jv:getRuntime(), concat('say --voice=Ava --rate=250 ', $text))"/>
Code: Select all
<xsl:value-of select="jv:exec(jv:getRuntime(), concat('say --voice=Ava --rate=250 --output-file=audio.m4a --file-format=m4af data-format=aac ', $text))"/>
My only thought is that from the command line, it knows where to put a file, in the "current working directory". I'm guessing that when executed within the Java environment as I am doing it within Oxygen, there is no definable "current working directory". Or at least not in a way that can be usable. Thus, it can't actually create the file anywhere. Can anyone comment on that?
Any insight into what might be going on here, how Oxygen, Java, and XSL are working together here, would be greatly appreciated!