c# - How to connect my Xamarin Android App to Google Speech Cloud API? -
i trying connect app google speech cloud, created credential is:
{ "type": "service_account", "project_id": "brastempinho", "private_key_id": "f87474dab95730dee217f6eb0cdb843c385cf2e3", "private_key": "-----begin private key-----\nmiievqibadanbgkqhkig9w0baqefaascbkcwggsjageaaoibaqcp2j74h/o1mx4f\n1w2hevajycqlqmqspxdnffbymr00dbjoiz4ghtwruqev7olrzez1veynhk0zkqd6\nzcoxjqllcczhavcudvixeqt0h2ssntimbjn9bvkwoysgeojaumtxfvfmyfv6vhdd\nqwgbazdyzz9efsxvnvimsrnr23uxbrweedk35sqo5xqimxhdfqrsoi/lgoza/1ne\nsgkxr7bhzgapwwpfiu2kgvfoltkypycy0djubnv8nv+wz+aqj1z9vsguznfjq3zj\nfw5u9o4f9j7yxfx1ucz1zwoegbcpbag7tij5wuwki3adgzz8qoiavdvc4ipjwzfw\njgvnhwvnagmbaaecggeadub3aj0ynvfc8ehixvg5ubai4f+l/v8tsyencfwru9hy\nyrsnuaolozwcnfstskerovt2bftxskpbnvzxnkuxgugi9hnzlqk26wsgwr0jpq5l\nepeixyesauib1qrgr+zuhnc4j9xuzogaqdn0xfib0zhsu89ffrxgciqhydq8bsdd\ng3+3xk8htslautg3nrrjzgy4+5y82qemfaqega59wic40ihxjejjwiccp9f5fjfu\njtxpdk/4rrlgj8gf5+wt6di6wilmby4uf5s8g9hhkifbbaur8est3ffdzfxubuxw\ntyvnk0lv3ffubqiogxeka2bqayxugpjcbejdhtp/kqkbgqdtnmie8yn2a2clvj9b\n0jh3njexqdjxrn9cjjn9orudrd8mfawstvzqlw2pbcwlsd5d+vadkn/xwjum+4xj\nttw/qgrg4jad+detyscgo648x1dwpw9f4dbafqpstufp2dk1vgx4niikb5pusmbn\n4ml1ql5p3skk6u245ioomjvecqkbgqdn4dvttdtaebrpiwh8ztykjq5+uuqcd7ic\nggp+911vovqrxliah35adowcrmgjg5+9l4mt9cqmf0qyzfgdblspteanqnps3wyc\n154+awmfhc4ghkwvu4ba4tsqeayzwdfyfop2hopzanwuyfywdhrq9rkcm1rdke9/\ni+nttohl1wkbgchi/h5e3kbhjvpgxn/frcwafo0ryqyabh0dqf1t1haanbm9554n\ngpmegwt265m9r5ngvasury53lstq+kdbtsz4zjqsjjpav4ukey4qfp2ewo+03mt0\n77caya0izijuzfzp5vhgodx9ompr1qxjwr3+twktkqxebn7zfdntxpjraogasilu\ny7hqivegsr61zw7gbq/kg+zjpwzqwwb6phjvnmiy+ndk30hvwln6fg3dsb6htezd\niocp5s5diwzb4aysrcgjclu2puummvmzd02yyfj2a1dzebuvzxnpe9zkcdirjcc4\ntzz3wdpm8a1jfxjpsytg8kfzqnviwnfsmapaftecgyeamag5myjsebbvtzp4trha\nhozhz+yreg+jgebd4a774esdza3vnabydxuq3+supda0dw5oox/laobudykjczyl\nvjsiobfiasmwjo26c1qjrx2lrym+bmvpgluhczyiozo13/6cchbqzk3amrbrinuj\ne07bia5narh+t6l+tvfaiwu=\n-----end private key-----\n", "client_email": "961053661712-compute@developer.gserviceaccount.com", "client_id": "108116634113879261923", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/961053661712-compute%40developer.gserviceaccount.com"
}
and code i'm using is:
using android.os; using android.support.v4.app; using android.views; using google.cloud.speech.v1; using system; using google.apis.auth.oauth2; using system.threading.tasks; using system.text; using system.io; using system.threading; using system.net.http; namespace whirlpoolapp.fragments { public class fragment1 : fragment { public override void oncreate(bundle savedinstancestate) { base.oncreate(savedinstancestate); task<string> cred = authenticateasync(); system.environment.setenvironmentvariable("google_application_credentials", "/storage/9016-4ef8/config/brastempinho-f87474dab957.json"); var speech = speechclient.create(); var response = speech.recognize(new recognitionconfig() { encoding = recognitionconfig.types.audioencoding.linear16, sampleratehertz = 16000, languagecode = "en", }, recognitionaudio.fromfile("audio.raw")); foreach (var result in response.results) { foreach (var alternative in result.alternatives) { console.writeline(alternative.transcript); } } } public static fragment1 newinstance() { var frag1 = new fragment1 { arguments = new bundle() }; return frag1; } public override view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { var ignored = base.oncreateview(inflater, container, savedinstancestate); return inflater.inflate(resource.layout.fragment1, null); } public async task<string> authenticateasync() { try { string filepath = path.combine("/storage/9016-4ef8/config/brastempinho-f87474dab957.json"); byte[] authbytes = null; filestream fs = new filestream(filepath, filemode.open, fileaccess.read); binaryreader br = new binaryreader(fs); long numbytes = new fileinfo(filepath).length; authbytes = br.readbytes((int)numbytes); //byte[] authbytes = await ileasync(filepath).configureawait(false); string authstring = encoding.ascii.getstring(authbytes); googlecredential credential = googlecredential.fromjson(authstring); credential = credential.createscoped("https://www.googleapis.com/auth/cloud-platform"); string token = await credential.underlyingcredential.getaccesstokenforrequestasync().configureawait(false); return token; } catch (exception e) { return e.message; } } }
}
my question is: how can call google speech cloud on xamarin android start using chatbot? want create app recognizes voices , transform on text talk bot ibm conversation does.
Comments
Post a Comment