Text to Speech enableTimePointing not working in Python - google-text-to-speech

Using texttospeech_v1beta1 to get ssml_mark but getting
"TypeError: synthesize_speech() got an unexpected keyword argument
'enableTimePointing'" error.
from google.cloud import texttospeech_v1beta1
client = texttospeech_v1beta1.TextToSpeechClient()synthesis_input = texttospeech_v1beta1.SynthesisInput(ssml=text)
voice = texttospeech_v1beta1.VoiceSelectionParams(language_code='tr-TR',name='tr-TR-Wavenet-E')
audio_config = texttospeech_v1beta1.AudioConfig(
audio_encoding=texttospeech_v1beta1.AudioEncoding.MP3)
response = client.synthesize_speech(input=synthesis_input, voice=voice, audio_config=audio_config, enableTimePointing = 'SSML_MARK')
print(response.timepoints)

You need to create a SynthesizeSpeechRequest Object instead of passing the arguments individually into client.synthesize_speech
So,
request = texttospeech_v1beta1.SynthesizeSpeechRequest(
input=synthesis_input,
voice=voice,
audio_config=audio_config,
enable_time_pointing=[texttospeech_v1beta1.SynthesizeSpeechRequest.TimepointType.SSML_MARK]
response = client.synthesize_speech(request)

Full example
from google.cloud.texttospeech_v1beta1 import VoiceSelectionParams, AudioConfig, AudioEncoding, SynthesizeSpeechRequest, SynthesisInput, TextToSpeechClient
client = TextToSpeechClient()
synthesis_input = SynthesisInput(ssml="<speak><mark name=\"1st\"/>Hello <mark name=\"2nd\"/>world</speak>")
voice = VoiceSelectionParams(language_code='en-US', name='en-US-Wavenet-D', ssml_gender='MALE')
audio_config = AudioConfig(audio_encoding=AudioEncoding.MP3)
request = SynthesizeSpeechRequest(input=synthesis_input, voice=voice, audio_config=audio_config, enable_time_pointing=[SynthesizeSpeechRequest.TimepointType.SSML_MARK])
response = client.synthesize_speech(request=request)
timepoints = list(response.timepoints)
# do something with timepoints

Related

Why i am getting authentication error in MATLAB while i try to use HTTP

I am trying to query SiriDB via Matlab. I am getting the positive response from my log-in attemps. However when i try to query, i get the error: "not authenticated".
Please see my code below:
clear;clc
import matlab.net.http.*
import matlab.net.http.field.*
import matlab.net.URI
import matlab.net.http.Credentials
strct1 = jsondecode('{"username": "my_user_name", "password": "my_password"}');
strct2 = jsondecode('{"query": "select last() from ''example_query''"}');
uri = 'http://example_adress/auth/login';
request = RequestMessage( 'POST',ContentTypeField( 'application/json'),strct1);
complete(request,uri);
response = send(request,uri);
complete(response);
response.Body.string
uri = 'http://example_api';
request = RequestMessage( 'POST',ContentTypeField( 'application/json'),strct2 );
complete(request,uri)
response = request.send( 'http://example_api' );
complete(response);
response.Body.string

Constructing params for Rest Api call issue

I have sample Python code and i am trying to construct and populate Rest API request parameters.
Headers and Authorization params are working fine but i am not sure how to translate below mention "QueryBands" and "data" variable for my Rest request using rest client.
queryBands = {}
queryBands['appName'] = 'MyApp'
queryBands['version'] = '1.0'
# Setting request fields, including SQL.
data = {}
data['query'] = 'SELECT * from db limit 5'
data['queryBands'] = queryBands
data['format'] = 'array'
request = urllib2.Request(url, json.dumps(data), headers)
try:
response = urllib2.urlopen(request);
Should i need to declare new variables or pass these values as "body" while doing Rest api call?
I am using chrome advance rest-client. But it could be any rest client.
import json
queryBands = {}
queryBands['applicationName'] = 'MyApp'
queryBands['version'] = '1.0'
data = {}
data['query'] = 'SELECT * from db limit 5'
data['queryBands'] = queryBands
data['format'] = 'array'
print(json.dumps(data))

get_process_lines in liquidsoap 1.3.0

I've just updated Liquidsoap to 1.3.0 and now get_process_lines does not return anything.
def get_request() =
# Get the URI
lines = get_process_lines("curl http://localhost:3000/api/v1/liquidsoap/next/my-radio")
log("liquidsoap curl returns #{lines}")
uri = list.hd(default="",lines)
log("liquidsoap will try and play #{uri}")
# Create a request
request.create(uri)
end
I read on the CHANGELOG
- Moved get_process_lines and get_process_output to utils.liq, added optional env parameter
Does it mean I have to do something to use utils.liq in my script now ?
The full script is as follows
set("log.file",false)
set("log.stdout",true)
set("log.level",3)
def apply_metadata(m) =
title = m["title"]
artist = m["artist"]
log("Now playing: #{title} by #{artist}")
end
# Our custom request function
def get_request() =
# Get the URI
lines = get_process_lines("curl http://localhost:3000/api/v1/liquidsoap/next/my-radio")
log("liquidsoap curl returns #{lines}")
uri = list.hd(default="",lines)
log("liquidsoap will try and play #{uri}")
# Create a request
request.create(uri)
end
def my_safe(s) =
security = sine()
fallback(track_sensitive=false,[s,security])
end
s = request.dynamic(id="s",get_request)
s = on_metadata(apply_metadata,s)
s = crossfade(s)
s = my_safe(s)
# We output the stream to an icecast
# server, in ogg/vorbis format.
log("liquidsoap starting")
output.icecast(
%mp3(id3v2=true,bitrate=128,samplerate=44100),
host = "localhost",
port = 8000,
password = "PASSWORD",
mount = "myradio",
genre="various",
url="http://www.myradio.fr",
description="My Radio",
s
)
Of course the API is working
$ curl http://localhost:3000/api/v1/liquidsoap/next/my-radio
annotate:title="Chamakay",artist="Blood Orange",album="Cupid Deluxe":http://localhost/stream/3.mp3
A more simple example :
lines = get_process_lines("echo hi")
log("lines = #{lines}")
line = list.hd(default="",lines)
log("line = #{line}")
returns the following logs
2017/05/05 15:24:42 [lang:3] lines = []
2017/05/05 15:24:42 [lang:3] line =
Many thanks in advance for your help !
geoffroy
The issue was fixed in liquidsoap 1.3.1
Fixed:
Fixed run_process, get_process_lines, get_process_output when compiling with OCaml <= 4.03 (#437, #439)
https://github.com/savonet/liquidsoap/blob/1.3.1/CHANGES#L12

get AT command call response

I'm trying a code to make a voice call using usb modem and it succeeded to make a call... now i want to get that call response to know if number is ringing,busy or unavailable
This is my used code:
string number = textBox1.Text;
po.PortName = "COM3";
po.BaudRate = int.Parse("9600");
po.DataBits = Convert.ToInt32("8");
po.Parity = Parity.None;
po.StopBits = StopBits.One;
po.ReadTimeout = int.Parse("300");
po.WriteTimeout = int.Parse("300");
po.Encoding = Encoding.GetEncoding("iso-8859-1");
po.Open();
po.DtrEnable = true;
po.RtsEnable = true;
po.Write("ATDT "+number+";\r");
System.Threading.Thread.Sleep(7000);
po.WriteLine("ATH+CHUP;\r");
po.DiscardInBuffer();
po.DiscardOutBuffer();
po.Close();
After ATD, you need reading the port for kind of information called URC.
For voice call, there are the following possible response,
If no dialtone
NO DIALTONE
If busy,
BUSY
If connection cannot be set up:
NO CARRIER
NO ANSWER
And, before ATD, you'd better set the error format using at+cmee, for exam, at+cmee=2 will enable the string format.
EDIT:(Here is an example with python)
#! /usr/bin/env python
# -*- coding: utf8 -*-
from __future__ import print_function
import sys
import serial
NUM = "111111111"
ser = serial.Serial("com1", 115200)
ser.write('at+cmee=2\r')
ser.timeout = 10.0
res = "invalid"
while len(res) > 0:
res = ser.read(1)
print(res, end='')
ser.write('atd' + NUM + ';\r')
ser.timeout = 60.0
res = "invalid"
while len(res) > 0:
res = ser.read(1)
print(res, end='')
ser.write("AT+CHUP\r")
ser.timeout = 10.0
res = "invalid"
while len(res) > 0:
res = ser.read(1)
print(res, end='')
Its output is (I reject the call from the phone "111111111"),
at+cmee=2
OK
atd111111111;
OK
NO CARRIER
AT+CHUP
+CME ERROR: operation not allowed
And, after the output of 'no carrier', there is no more need to hang up.

Matlab urlread2 - HTTP response code: 415 for URL

I am attempting to access the betfair API using Matlab and the urlread2 function available here.
EDIT: I have posted this problem on Freelancer if anyone can help with it: tinyurl.../pa7sblb
The documentation for the betfair API I am following is this getting started guide. I have successfully logged in and kept the session open using these codes: (I am getting a success response)
%% Login and get Token
url = 'https://identitysso.betfair.com/api/login';
params = {'username' '******' 'password' '******'};
header1 = http_createHeader('X-Application','*****');
header2 = http_createHeader('Accept','application/json');
header = [header1, header2];
[paramString] = http_paramsToString(params)
[login,extras] = urlread2(url,'POST',paramString,header)
login = loadjson(login)
token = login.token
%% Keep Alive
disp('Keep Session Alive')
url_alive = 'https://identitysso.betfair.com/api/keepAlive';
header1 = http_createHeader('X-Application','******');
header2 = http_createHeader('Accept','application/json');
header3 = http_createHeader('X-Authentication',token');
header_alive = [header1, header2, header3];
[keep_alive,extras] = urlread2(url_alive,'POST',[],header_alive);
keep_alive = loadjson(keep_alive);
keep_alive_status = keep_alive.status
My trouble starts when I am attempting to do the next step and load all available markets. I am trying to replicate this example code which is designed for Python
import requests
import json
endpoint = "https://api.betfair.com/exchange/betting/rest/v1.0/"
header = { 'X-Application' : 'APP_KEY_HERE', 'X-Authentication' : 'SESSION_TOKEN_HERE' ,'content-type' : 'application/json' }
json_req='{"filter":{ }}'
url = endpoint + "listEventTypes/"
response = requests.post(url, data=json_req, headers=header)
The code I am using for Matlab is below.
%% Get Markets
url = 'https://api.betfair.com/exchange/betting/rest/v1.0/listEventTypes/';
header_application = http_createHeader('X-Application','******');
header_authentication = http_createHeader('X-Authentication',token');
header_content = http_createHeader('content_type','application/json');
header_list = [header_application, header_authentication, header_content];
json_body = savejson('','filter: {}');
[list,extras] = urlread2(url_list,'POST',json_body,header_list)
I am having trouble with a http response code 415. I believe that the server cannot understand my parameter since the headings I have used with success previously.
Any help or advice would be greatly appreciated!
This is the error:
Response stream is undefined
below is a Java Error dump (truncated):
Error using urlread2 (line 217)
Java exception occurred:
java.io.IOException: Server returned HTTP response code: 415 for URL....
I looked at your problem and it seems to be caused by two things:
1) The content type should be expressed as 'content-type' and not 'content_type'
2) The savejson-function doesn't create an adequate json-string. If you use the json-request from the Python-script it works.
This code work for me:
%% Get Markets
url = 'https://api.betfair.com/exchange/betting/rest/v1.0/listEventTypes/';
header_application = http_createHeader('X-Application','*********');
header_authentication = http_createHeader('X-Authentication',token');
header_content = http_createHeader('content-type','application/json');
header_list = [header_application, header_authentication, header_content];
json_body = '{"filter":{ }}';
[list,extras] = urlread2(url,'POST',json_body,header_list)