Google text to speech - SSML breaks missing from mp3 output - google-text-to-speech

Am experiencing an issue with SSML tags being 'dropped' when converting base-64 output from Google Text to Speech to an MP3 file.
Platform is OSX 10.12.6.
My syntax seems to be fine and tests OK with other services but, when I convert it through terminal it drops all my SSML.
Have been messing around trying different things for the last 8 hours!
My call to the API is:
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'input':{
'ssml':'<speak>
First sentence<break time="3s"/>
Second sentence <break time="300ms"/><say-as interpret-as="date" format="yyyy" detail="1">1919</say-as><break time="2s"/>
Third sentence <say-as interpret-as="characters">send</say-as> <break time="300ms"/><say-as interpret-as="date" format="yyyy" detail="1">2016</say-as><break time="2s"/>
Fourth sentence <say-as interpret-as="cardinal">10456</say-as> <break time="300ms"/><say-as interpret-as="date" format="yyyy" detail="1">2017</say-as><break time="2s"/>
Fifth sentence <say-as interpret-as="unit">10 foot</say-as> <break time="300ms"/><say-as interpret-as="time" format="hms12">3:30am</say-as><break time="2s"/>
</speak>'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Wavenet-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3',
'pitch': '0',
'speakingRate': '0.90'
}
}" "https://texttospeech.googleapis.com/v1/text:synthesize" > complex-test.txt
And then the output is converted to MP3 using:
sed 's|audioContent| |' < complex-test.txt > tmp-output.txt && \
tr -d '\n ":{}' < tmp-output.txt > tmp-output-2.txt && \
base64 tmp-output-2.txt --decode > complex-test.mp3 && \
rm tmp-output*.txt
The output is just one rapid fire spoken track with no breaks and none of the SSML tags work.
Any fresh ideas appreciated!
Many thanks.

Related

Change variable value in Script shell with sed command ; error syntax

sed -i 's|from_infura_hex=?|from_infura_hex=$(curl -s -X POST --connect-timeout 5 -H "Content-Type: application/json" --data \'{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}\' https://ropsten.infura.io/X/X | jq .result | xargs)|' /home/ec2-user/LastBlockNode.sh
I tried to execute this command but I always get this error:
-bash: syntax error near unexpected token `)'
The purpose of this command is to modify the value from_infura_hex=? in the script LastBlockNode.sh by the curl command.
Can anyone help with this sed command?
If you choose a pipe character | as a delimiter for s command,
the character should not appear in pattern or replacement without escaping. As you are using | as a pipeline in your command, it is better to pick other character such as #.
You cannot nest single quotes even if you escape it with a backslash.
In order to use a command substitution within the replacement,
you need to say sed -i '/pattern/'"$(command)"'/', not
sed -i '/pattern/$(command)/'.
Then would you please try something like:
sed -i 's#from_infura_hex=?#from_infura_hex='"$(curl -s -X POST --connect-timeout 5 -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":
\"eth_blockNumber\",\"params\":[],\"id\":1}" https://ropsten.infura.io/X/X | jq .result | xargs)"'#' /home/ec2-user/LastBlockNode.sh
But it will be safer and more readable to split the command into
multiple lines:
replacement="$(curl -s -X POST --connect-timeout 5 -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://ropsten.infura.io/X/X | jq .result | xargs)"
sed -i 's#from_infura_hex=?#from_infura_hex='"$replacement"'#' /home/ec2-user/LastBlockNode.sh
Please note I have not tested the commands above with the actual data.
If either of them still do not work, please let me know with the error message.

How to use gnuplot xdata time with feedgnuplot?

I'm using feedgnuplot and gnuplot to show real-time data on my linux desktop.
My data is produced by command which outputs 12 space separated integer values on each line and up to four lines per second.
I like to add the time, so I put time in front of the line before feeding data to feedgnuplot.
If I specify the time as seconds, the data is properly plotted, but the x-axis is quite unreadable:
data-producer |
while read -a line
do
echo -n $(date +"%s")
for n in "${line[#]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%s'"
So I tried to get human readable time on the horizontal scale:
data-producer |
while read -a line
do
echo -n $(date +"%H:%M:%S")
for n in "${line[#]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%H:%M:%S'"
This line does not work because feedgnuplot complains about comparison operators not applied to numeric data:
Argument "09:45:58" isn't numeric in numeric lt (<) at /usr/bin/feedgnuplot line 694.
Argument "09:45:57" isn't numeric in numeric ge (>=) at /usr/bin/feedgnuplot line 797.
Looking into the feedgnuplot code (it is a perl script) I see that comparison is performed on x values to sort them and to assess whether the graph has to be plotted again or not.
Is it possible to have feedgnuplot handle times by using some command line switches? If not, is there any other option before resorting to patching the feedgnuplot source code? Thank you.
Gnuplot requires some special settings for datetime data (e.g. a using statement must be specified). Therefore, feedgnuplot provides an own option for time data, --timefmt <format>:
for i in `seq 0 100`; do echo $i; sleep 1; done |
while read -a line
do
echo -n $(date +"%Y-%m-%d %H:%M:%S")
for n in "${line[#]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--lines \
--timefmt "%Y-%m-%d %H:%M:%S" \
--set 'format x "%H:%M:%S"'
Note, that different versions of gnuplot use different reference points for time in seconds, so that versions 4.6 (reference 1st January 2000) and earlier give wrong results when using %s. So it is better to use a time format of the kind %H:%M:%S. In the code above I used a fully defined datetime to avoid possible problems with day-spanning plots.

How to see the search found using curl o wget?

I need to see the searches found using curl or wget , when it find results with '301' status code.
This is my variable using curl.
website=$(curl -s --head -w %{http_code} https://launchpad.net/~[a-z]/+archive/pipelight -o /dev/null | sed 's#404##g')
echo $website
301
The above works, but only display if the site exists with '301' status code.
I want
echo $website
https://launchpad.net/~mqchael/+archive/pipelight
You can add the "effective URL" to your output. Change %{http_code} to "%{http_code} %{url_effective} ".
From there, it's just a matter of fussing with the regular expression. Change the sed string to 's#404 [^ ]* ##g'. That will eliminate (assuming you don't already know) not just the 404s, but will also eat the URL that follows it.
So:
curl -s --head -w "%{http_code} %{url_effective} " https://launchpad.net/~[a-z]/+archive/pipelight -o /dev/null | sed 's#404 [^ ]* ##g''s#404 [^ ]* ##g'
will give you:
301 https://launchpad.net/~j/+archive/pipelight
You may want to replace the HTTP codes with new-lines, after that.

In zenity forms, how can I set default values (initialize) entries?

I've got a zenity form working, but I can't find any information on initializing the entries. The Zenity help manual webpage doesn't address the issue.
For example, the example from that webpage is
#!/bin/sh
zenity --forms --title="Add Friend" \
--text="Enter information about your friend." \
--separator="," \
--add-entry="First Name" \
--add-entry="Family Name" \
--add-entry="Email" \
--add-calendar="Birthday" >> addr.csv
case $? in
0)
echo "Friend added.";;
1)
echo "No friend added."
;;
-1)
echo "An unexpected error has occurred."
;;
esac
How would I initialize First Name, Last Name, etc. before displaying the window?
Use yad. It's a fork of zenity that I ended up using to overcome this missing functionality in zenity. The key is to use the --form option and include the initial values on the command line after the defined options and parameters. This "extra data" is assumed to be initial values for the fields.
initial_name_data='Jane Doe'; initial_email_data='jane#doe.org'
yad --form --title='Contact Info' --text='Edit Data' --field=Name --field=Email "$initial_name_data" "$initial_email_data"
yad --form --title='Contact Info' --text='Edit Data' --field=Name:CB --field=Email 'Joe Cool!^Jane Doe!Write Another Name' "JoeCool#home.net"
Joe Cool|JoeCool#home.net|
You should start the default option with ^ and separate each one with ! (notice that I enclose all of them with ' ... '

Xmlstarlet and sed to replace string in a file

I have huge number of html files. I need to replace all the , and " with html entities &nsbquo and &quto respectively.
I need to succeed in two steps for this:
1) Find all the text between tags. I need to replace only in this text between tags.
2) Replace all required strings using sed
My command for this is :
xmlstarlet sel -t -v "*//p" "index.html" | sed 's/,/\&nsbquo/'
This works, but now I dont know how to put back the changes to index.html file.
In sed we have -i option, but for that I need to specify the filename with sed command. But in my case, i have to use | to filter out the required string from html file.
Please help. I did a lot of search for this from 2 days but no luck.
Thank you,
Divya.
The main problem here is that in XML there is no difference between " and ", so you can't use xmlstarlet to do this directly. You could replace " with a special string and then use sed to replace that with ":
xmlstarlet ed -u "//p/text()" \
-x "str:replace(str:replace(., ',', '#NSBQUO#'), '\"', '#QUOT#')" \
quote.html | \
sed 's/#NSBQUO#/\&nsbquo\;/g; s/#QUOT#/\&quot\;/g' > quote-new.html
mv quote-new.html quote.html
NOTE: str:replace and other exslt functions were only added to xmlstarlet ed in version 1.3.0, so it was not available at the time this question was asked.