Create a gist now

Instantly share code, notes, and snippets.

Cloud Speech API and Natural Language JSON from teowaki's blog post
{
"config": {
"encoding":"FLAC",
"sample_rate": 16000,
"languageCode": "en-GB"
},
"audio": {
"uri":"gs://formatinternet_misc/theresa_may_mp_extract.flac"
}
}
{
"results": [
{
"alternatives": [
{
"transcript": "that means fighting against the burning injustice but if you're born poor you will die on average 9 years earlier than others if you're black you're treated more harshly by the criminal justice system then if your weight is there a white working class boy you're less likely than anybody else in Britain to go to university is right Estate school you're less likely to reach the top professions then if your educated privately if you're a woman you will earn less than a man if you suffer from mental health problem there's not enough help to hand if you're young you'll find it harder than ever before to own your own home",
"confidence": 0.935612
}
]
}
]
}
{
"document":{
"type":"PLAIN_TEXT",
"content":"that means fighting against the burning injustice but if you're born poor you will die on average 9 years earlier tha
n others if you're black you're treated more harshly by the criminal justice system then if your weight is there a white working cla
ss boy you're less likely than anybody else in Britain to go to university is right Estate school you're less likely to reach the to
p professions then if your educated privately if you're a woman you will earn less than a man if you suffer from mental health probl
em there's not enough help to hand if you're young you'll find it harder than ever before to own your own home"
},
"features": {
"extractDocumentSentiment": true,
"extractEntities": true
}
}
{
"sentences": [],
"tokens": [],
"entities": [
{
"name": "Britain",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/United_Kingdom"
},
"salience": 0.010285536,
"mentions": [
{
"text": {
"content": "Britain",
"beginOffset": -1
}
}
]
}
],
"documentSentiment": {
"polarity": -1,
"magnitude": 0.7
},
"language": "en"
}
{
"document":{
"type":"PLAIN_TEXT",
"content":"I have just been to Buckingham Palace, where Her Majesty The Queen has asked me to form a new government, and I accep
ted.
In David Cameron, I follow in the footsteps of a great, modern Prime Minister. Under David’s leadership, the government stabilised t
he economy, reduced the budget deficit, and helped more people into work than ever before.
But David’s true legacy is not about the economy but about social justice. From the introduction of same-sex marriage, to taking peo
ple on low wages out of income tax altogether; David Cameron has led a one-nation government, and it is in that spirit that I also p
lan to lead.
Because not everybody knows this, but the full title of my party is the Conservative and Unionist Party, and that word ‘unionist’ is
very important to me.
It means we believe in the Union: the precious, precious bond between England, Scotland, Wales and Northern Ireland. But it means so
mething else that is just as important; it means we believe in a union not just between the nations of the United Kingdom but betwee
n all of our citizens, every one of us, whoever we are and wherever we’re from.
That means fighting against the burning injustice that, if you’re born poor, you will die on average 9 years earlier than others.
If you’re black, you’re treated more harshly by the criminal justice system than if you’re white.
If you’re a white, working-class boy, you’re less likely than anybody else in Britain to go to university.
If you’re at a state school, you’re less likely to reach the top professions than if you’re educated privately.
If you’re a woman, you will earn less than a man. If you suffer from mental health problems, there’s not enough help to hand.
If you’re young, you’ll find it harder than ever before to own your own home.
But the mission to make Britain a country that works for everyone means more than fighting these injustices. If you’re from an ordin
ary working class family, life is much harder than many people in Westminster realise. You have a job but you don’t always have job
security. You have your own home, but you worry about paying a mortgage. You can just about manage but you worry about the cost of l
iving and getting your kids into a good school.
If you’re one of those families, if you’re just managing, I want to address you directly.
I know you’re working around the clock, I know you’re doing your best, and I know that sometimes life can be a struggle. The governm
ent I lead will be driven not by the interests of the privileged few, but by yours.
We will do everything we can to give you more control over your lives. When we take the big calls, we’ll think not of the powerful,
but you. When we pass new laws, we’ll listen not to the mighty but to you. When it comes to taxes, we’ll prioritise not the wealthy,
but you. When it comes to opportunity, we won’t entrench the advantages of the fortunate few. We will do everything we can to help
anybody, whatever your background, to go as far as your talents will take you.
We are living through an important moment in our country’s history. Following the referendum, we face a time of great national chang
e.
And I know because we’re Great Britain, that we will rise to the challenge. As we leave the European Union, we will forge a bold new
positive role for ourselves in the world, and we will make Britain a country that works not for a privileged few, but for every one
of us.
That will be the mission of the government I lead, and together we will build a better Britain."
},
"features": {
"extractDocumentSentiment": true,
"extractEntities": true
}
}
{
"sentences": [],
"tokens": [],
"entities": [
{
"name": "Britain",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/United_Kingdom"
},
"salience": 0.010285536,
"mentions": [
{
"text": {
"content": "Britain",
"beginOffset": -1
}
}
]
}
],
"documentSentiment": {
"polarity": -1,
"magnitude": 0.7
},
"language": "en"
}
javier@javier-teowaki:~/temp$ curl -s -k -H "Content-Type: application/json" -H "Authorization: Bearer ya29.Ci8nA8vXgbR9VQ9NtXbhpj3Nz1oLwzShqn0gt0Ts2RnrCR-UDHg9W-mynn_WERa_9Q" https://language.googleapis.com/v1beta1/documents:annotateText -d @nlp_may_full.json
{
"sentences": [],
"tokens": [],
"entities": [
{
"name": "Buckingham Palace",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Buckingham_Palace"
},
"salience": 0.099641077,
"mentions": [
{
"text": {
"content": "Buckingham Palace",
"beginOffset": -1
}
}
]
},
{
"name": "Conservative and Unionist Party",
"type": "ORGANIZATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Conservative_Party_(UK)"
},
"salience": 0.055497561,
"mentions": [
{
"text": {
"content": "Conservative and Unionist Party",
"beginOffset": -1
}
}
]
},
{
"name": "David Cameron",
"type": "PERSON",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/David_Cameron"
},
"salience": 0.049396969,
"mentions": [
{
"text": {
"content": "David Cameron",
"beginOffset": -1
}
},
{
"text": {
"content": "David",
"beginOffset": -1
}
},
{
"text": {
"content": "David",
"beginOffset": -1
}
},
{
"text": {
"content": "David Cameron",
"beginOffset": -1
}
}
]
},
{
"name": "United Kingdom",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/United_Kingdom"
},
"salience": 0.015252167,
"mentions": [
{
"text": {
"content": "United Kingdom",
"beginOffset": -1
}
},
{
"text": {
"content": "Britain",
"beginOffset": -1
}
},
{
"text": {
"content": "Britain",
"beginOffset": -1
}
},
{
"text": {
"content": "Britain",
"beginOffset": -1
}
}
]
},
{
"name": "Her Majesty The Queen",
"type": "ORGANIZATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Elizabeth_II"
},
"salience": 0.0072650528,
"mentions": [
{
"text": {
"content": "Her Majesty The Queen",
"beginOffset": -1
}
}
]
},
{
"name": "Union",
"type": "OTHER",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Trade_union"
},
"salience": 0.002490957,
"mentions": [
{
"text": {
"content": "Union",
"beginOffset": -1
}
}
]
},
{
"name": "me.It",
"type": "OTHER",
"metadata": {},
"salience": 0.0016241936,
"mentions": [
{
"text": {
"content": "me.It",
"beginOffset": -1
}
}
]
},
{
"name": "England",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/England"
},
"salience": 0.0016241936,
"mentions": [
{
"text": {
"content": "England",
"beginOffset": -1
}
}
]
},
{
"name": "Scotland",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Scotland"
},
"salience": 0.0016241936,
"mentions": [
{
"text": {
"content": "Scotland",
"beginOffset": -1
}
}
]
},
{
"name": "Wales",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Wales"
},
"salience": 0.0016241936,
"mentions": [
{
"text": {
"content": "Wales",
"beginOffset": -1
}
}
]
},
{
"name": "Northern Ireland",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Northern_Ireland"
},
"salience": 0.0016241936,
"mentions": [
{
"text": {
"content": "Northern Ireland",
"beginOffset": -1
}
}
]
},
{
"name": "Britain",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/United_Kingdom"
},
"salience": 0.0013228959,
"mentions": [
{
"text": {
"content": "Britain",
"beginOffset": -1
}
}
]
},
{
"name": "Great Britain",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Great_Britain"
},
"salience": 0.00090130843,
"mentions": [
{
"text": {
"content": "Great Britain",
"beginOffset": -1
}
}
]
},
{
"name": "European Union",
"type": "ORGANIZATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/European_Union"
},
"salience": 0.00089618628,
"mentions": [
{
"text": {
"content": "European Union",
"beginOffset": -1
}
}
]
},
{
"name": "Westminster",
"type": "LOCATION",
"metadata": {
"wikipedia_url": "http://en.wikipedia.org/wiki/Westminster"
},
"salience": 0.000877493,
"mentions": [
{
"text": {
"content": "Westminster",
"beginOffset": -1
}
}
]
}
],
"documentSentiment": {
"polarity": 0.1,
"magnitude": 9.7
},
"language": "en"
}
@finlaand

Good stuff at the Google event :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment