Python中文
首页
教程
问答
标签
搜索
登录
注册
谷歌语音Api v1不工作?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我用Google speech Api v1开发了一个应用程序</p> <blockquote> <p><a href="https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=" rel="noreferrer">https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=</a>"+language_code; </p> </blockquote> <p>这个链接被用来得到回应。它工作得很好,但就从今天开始它就不工作了。我没有得到任何回应,从这个环节。有人知道吗?有没有其他的链接?请帮忙</p> <pre><code> protected String doInBackground(Void... params) { // TODO Auto-generated method stub String urlString = "https://www.google.com/speech-api/v2/recognize?xjerr=1&client=chromium&lang=" + language_code; // String urlString = "https://www.google.com/speech-api/v2/recognize? output=json&lang="+language_code+"s&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4"; // Log.e("SpeechRecognizer url : ", urlString); // String urlString = // "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=speech2text&lang=" // + language_code; URL url; try { Log.e("", "started speech to text"); FLAC_FileEncoder fileEncoder = new FLAC_FileEncoder(); File inputfile = new File(Environment.getExternalStorageDirectory() .getPath() + "/SpeechLibrary/speech.wav"); File outputfile = new File(Environment .getExternalStorageDirectory().getPath() + "/SpeechLibrary/speech.flac"); fileEncoder.encode(inputfile, outputfile); url = new URL(urlString); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDefaultUseCaches(true); con.setConnectTimeout(20000); con.setReadTimeout(60000); con.setDoInput(true); con.setDoOutput(true); con.setInstanceFollowRedirects(true); con.setRequestMethod("POST"); // con.setRequestProperty("User-Agent", // "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12"); con.setRequestProperty("Content-Type", "audio/x-flac;rate=16000"); File file = new File(Environment.getExternalStorageDirectory() .getPath() + "/SpeechLibrary/speech.flac"); byte[] buffer = new byte[(int) file.length()]; FileInputStream fis = new FileInputStream(file); fis.read(buffer); fis.close(); OutputStream os = con.getOutputStream(); os.write(buffer); os.close(); con.connect(); con.getResponseMessage(); InputStreamReader inputStreamReader = new InputStreamReader( con.getInputStream(), "UTF-8"); BufferedReader br = new BufferedReader(inputStreamReader); String s; StringBuilder resultContent = new StringBuilder(); while ((s = br.readLine()) != null) { resultContent.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(s + "\n"); } JSONObject jsonResponse = new JSONObject(resultContent.toString()); JSONArray jsonArray = jsonResponse.getJSONArray("hypotheses"); Log.e("Response String: ", resultContent.toString()); if (jsonArray.length() != 0) { output = jsonArray.getJSONObject(0).getString("utterance"); confidence_level = Double.parseDouble(jsonArray .getJSONObject(0).getString("confidence")); } else if (jsonArray.length() == 0) { } // output=resultContent.toString(); } catch (Exception e) { output = ""; confidence_level = -1; e.printStackTrace(); Log.e("ERROR IN PARSING:", e.toString()); if (e.toString().contains("java.net.UnknownHostException:")||e.toString().contains("java.net.SocketException")) { return "NETWORK ISSUE"; } } return null; } </code></pre> <p>还有人有同样的问题吗?。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>如果您正在寻找Java API,请检查<a href="https://github.com/The-Shadow/java-speech-api" rel="nofollow">this</a>一个。它支持新的双工API和V2 API。还提供了一个方便的教程。在Google关闭V1之前迁移可能是一个好主意,如果他们还没有。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在Excel中读取公式并将其转换为Python中的计算?
4 回答
如何在excel中读取嵌入的excel,并将嵌入文件中的信息存储在主excel文件中?
2 回答
如何在Excel中返回未知列长度的非空顶行列值?
4 回答
如何在excel中选择数据列?
3 回答
如何在Excel中通过脚本自动为一列中的所有单元格创建公共别名
4 回答
如何在excel中高效格式化范围AttributeError:“tuple”对象没有属性“fill”
5 回答
如何在excel单元格中编写python函数
7 回答
如何在excel单元格中自动执行此python代码?
3 回答
如何在excel工作表中创建具有相应值的新列
2 回答
如何在Excel工作表中复制条件为单元格颜色的python数据框?
5 回答
如何在Excel工作表中循环
1 回答
如何在excel工作表中打印嵌套词典?
1 回答
如何在excel工作表中绘制所有类的继承树?
5 回答
如何在Excel工作表中自动调整列宽?
1 回答
如何在excel工作表中追加并进一步处理
6 回答
如何在excel工作表之间进行更改?
8 回答
如何在excel或csv上获取selenium数据?
7 回答
如何在Excel或Python中将正确的值赋给正确的列
7 回答
如何在excel或python中提取单词周围的文本?
7 回答
如何在excel或python中转换来自Jira的3w 1d 4h的fromat数据?
4 回答