Google STT with Pandas - how to transpose columns












0














I am new to Python, and working on a project with Google Speech to text. Finally figured out how to import results of Google STT (JSON) and format data in csv. BUT....



Google gives you alternative words which is good and bad. The attached code will only read the first alternative and stop, so I can only select one alternative.



I would love to import the other alternatives and show in their own column it Main, alt1, alt2. Sometimes time stamps the same as Main, sometimes differ.



Advice appreciated. - feeling I am getting the hang of it slowly.



{
"@type": "type.googleapis.com/google.cloud.speech.v1p1beta1.LongRunningRecognizeResponse",
"timestamp": "2018-12-28 14:13:18",
"results": [
{
"alternatives": [
{
"confidence": 0.9319887,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla1a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla1b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95174015,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla2a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla2b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95298487,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "bla3b"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla3b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.8774771,
"words": [
{
"confidence": 0.7337543,
"endTime": "3s",
"startTime": "2s",
"word": "Bla4a"
},
{
"confidence": 0.9363319,
"endTime": "4s",
"startTime": "3s",
"word": "bla4b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.9491383,
"words": [
{
"confidence": 0.8349256,
"endTime": "4s",
"startTime": "3s",
"word": "Bla5a"
},
{
"confidence": 0.9572171,
"endTime": "5s",
"speakerTag": 1,
"startTime": "4s",
"word": "Bla5b"
}
]
}
],
"languageCode": "th-th"
}
]
}



#!/usr/bin/python
# note = can only show one alternatives list
import json
import pandas as pd
from pandas import ExcelWriter
import numpy as np

with open('Thai_Unicode(bk).json') as f: # this ensures opening and closing file
a = json.loads(f.read())

data = a["results"][0]["alternatives"][0]["words"]

df = pd.DataFrame(data)

#print(df)

df.to_excel('pandas4.xls')









share|improve this question
























  • how to delete :(. wanted to post code and json sample too
    – user966885
    Dec 28 '18 at 7:39












  • Click the "edit" button and supply additional info as needed.
    – coldspeed
    Dec 28 '18 at 7:49










  • Happy I can get the results in a xls, but problem is I there are alternative speech conversions ( different words ) , would like to see them next to the same time stamp
    – user966885
    Dec 28 '18 at 10:04
















0














I am new to Python, and working on a project with Google Speech to text. Finally figured out how to import results of Google STT (JSON) and format data in csv. BUT....



Google gives you alternative words which is good and bad. The attached code will only read the first alternative and stop, so I can only select one alternative.



I would love to import the other alternatives and show in their own column it Main, alt1, alt2. Sometimes time stamps the same as Main, sometimes differ.



Advice appreciated. - feeling I am getting the hang of it slowly.



{
"@type": "type.googleapis.com/google.cloud.speech.v1p1beta1.LongRunningRecognizeResponse",
"timestamp": "2018-12-28 14:13:18",
"results": [
{
"alternatives": [
{
"confidence": 0.9319887,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla1a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla1b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95174015,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla2a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla2b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95298487,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "bla3b"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla3b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.8774771,
"words": [
{
"confidence": 0.7337543,
"endTime": "3s",
"startTime": "2s",
"word": "Bla4a"
},
{
"confidence": 0.9363319,
"endTime": "4s",
"startTime": "3s",
"word": "bla4b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.9491383,
"words": [
{
"confidence": 0.8349256,
"endTime": "4s",
"startTime": "3s",
"word": "Bla5a"
},
{
"confidence": 0.9572171,
"endTime": "5s",
"speakerTag": 1,
"startTime": "4s",
"word": "Bla5b"
}
]
}
],
"languageCode": "th-th"
}
]
}



#!/usr/bin/python
# note = can only show one alternatives list
import json
import pandas as pd
from pandas import ExcelWriter
import numpy as np

with open('Thai_Unicode(bk).json') as f: # this ensures opening and closing file
a = json.loads(f.read())

data = a["results"][0]["alternatives"][0]["words"]

df = pd.DataFrame(data)

#print(df)

df.to_excel('pandas4.xls')









share|improve this question
























  • how to delete :(. wanted to post code and json sample too
    – user966885
    Dec 28 '18 at 7:39












  • Click the "edit" button and supply additional info as needed.
    – coldspeed
    Dec 28 '18 at 7:49










  • Happy I can get the results in a xls, but problem is I there are alternative speech conversions ( different words ) , would like to see them next to the same time stamp
    – user966885
    Dec 28 '18 at 10:04














0












0








0







I am new to Python, and working on a project with Google Speech to text. Finally figured out how to import results of Google STT (JSON) and format data in csv. BUT....



Google gives you alternative words which is good and bad. The attached code will only read the first alternative and stop, so I can only select one alternative.



I would love to import the other alternatives and show in their own column it Main, alt1, alt2. Sometimes time stamps the same as Main, sometimes differ.



Advice appreciated. - feeling I am getting the hang of it slowly.



{
"@type": "type.googleapis.com/google.cloud.speech.v1p1beta1.LongRunningRecognizeResponse",
"timestamp": "2018-12-28 14:13:18",
"results": [
{
"alternatives": [
{
"confidence": 0.9319887,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla1a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla1b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95174015,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla2a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla2b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95298487,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "bla3b"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla3b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.8774771,
"words": [
{
"confidence": 0.7337543,
"endTime": "3s",
"startTime": "2s",
"word": "Bla4a"
},
{
"confidence": 0.9363319,
"endTime": "4s",
"startTime": "3s",
"word": "bla4b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.9491383,
"words": [
{
"confidence": 0.8349256,
"endTime": "4s",
"startTime": "3s",
"word": "Bla5a"
},
{
"confidence": 0.9572171,
"endTime": "5s",
"speakerTag": 1,
"startTime": "4s",
"word": "Bla5b"
}
]
}
],
"languageCode": "th-th"
}
]
}



#!/usr/bin/python
# note = can only show one alternatives list
import json
import pandas as pd
from pandas import ExcelWriter
import numpy as np

with open('Thai_Unicode(bk).json') as f: # this ensures opening and closing file
a = json.loads(f.read())

data = a["results"][0]["alternatives"][0]["words"]

df = pd.DataFrame(data)

#print(df)

df.to_excel('pandas4.xls')









share|improve this question















I am new to Python, and working on a project with Google Speech to text. Finally figured out how to import results of Google STT (JSON) and format data in csv. BUT....



Google gives you alternative words which is good and bad. The attached code will only read the first alternative and stop, so I can only select one alternative.



I would love to import the other alternatives and show in their own column it Main, alt1, alt2. Sometimes time stamps the same as Main, sometimes differ.



Advice appreciated. - feeling I am getting the hang of it slowly.



{
"@type": "type.googleapis.com/google.cloud.speech.v1p1beta1.LongRunningRecognizeResponse",
"timestamp": "2018-12-28 14:13:18",
"results": [
{
"alternatives": [
{
"confidence": 0.9319887,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla1a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla1b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95174015,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "Bla2a"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla2b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.95298487,
"words": [
{
"confidence": 0.9572171,
"endTime": "2s",
"startTime": "1s",
"word": "bla3b"
},
{
"confidence": 0.9572171,
"endTime": "3s",
"startTime": "2s",
"word": "Bla3b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.8774771,
"words": [
{
"confidence": 0.7337543,
"endTime": "3s",
"startTime": "2s",
"word": "Bla4a"
},
{
"confidence": 0.9363319,
"endTime": "4s",
"startTime": "3s",
"word": "bla4b"
}
]
}
],
"languageCode": "th-th"
},
{
"alternatives": [
{
"confidence": 0.9491383,
"words": [
{
"confidence": 0.8349256,
"endTime": "4s",
"startTime": "3s",
"word": "Bla5a"
},
{
"confidence": 0.9572171,
"endTime": "5s",
"speakerTag": 1,
"startTime": "4s",
"word": "Bla5b"
}
]
}
],
"languageCode": "th-th"
}
]
}



#!/usr/bin/python
# note = can only show one alternatives list
import json
import pandas as pd
from pandas import ExcelWriter
import numpy as np

with open('Thai_Unicode(bk).json') as f: # this ensures opening and closing file
a = json.loads(f.read())

data = a["results"][0]["alternatives"][0]["words"]

df = pd.DataFrame(data)

#print(df)

df.to_excel('pandas4.xls')






pandas google-speech-api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 10:00







user966885

















asked Dec 28 '18 at 7:37









user966885user966885

12




12












  • how to delete :(. wanted to post code and json sample too
    – user966885
    Dec 28 '18 at 7:39












  • Click the "edit" button and supply additional info as needed.
    – coldspeed
    Dec 28 '18 at 7:49










  • Happy I can get the results in a xls, but problem is I there are alternative speech conversions ( different words ) , would like to see them next to the same time stamp
    – user966885
    Dec 28 '18 at 10:04


















  • how to delete :(. wanted to post code and json sample too
    – user966885
    Dec 28 '18 at 7:39












  • Click the "edit" button and supply additional info as needed.
    – coldspeed
    Dec 28 '18 at 7:49










  • Happy I can get the results in a xls, but problem is I there are alternative speech conversions ( different words ) , would like to see them next to the same time stamp
    – user966885
    Dec 28 '18 at 10:04
















how to delete :(. wanted to post code and json sample too
– user966885
Dec 28 '18 at 7:39






how to delete :(. wanted to post code and json sample too
– user966885
Dec 28 '18 at 7:39














Click the "edit" button and supply additional info as needed.
– coldspeed
Dec 28 '18 at 7:49




Click the "edit" button and supply additional info as needed.
– coldspeed
Dec 28 '18 at 7:49












Happy I can get the results in a xls, but problem is I there are alternative speech conversions ( different words ) , would like to see them next to the same time stamp
– user966885
Dec 28 '18 at 10:04




Happy I can get the results in a xls, but problem is I there are alternative speech conversions ( different words ) , would like to see them next to the same time stamp
– user966885
Dec 28 '18 at 10:04












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53955174%2fgoogle-stt-with-pandas-how-to-transpose-columns%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53955174%2fgoogle-stt-with-pandas-how-to-transpose-columns%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas