首页 版块 访问AI主站 注册 发帖
xahef
9
积分 积分商城
0
获赞
错误代码3302,我明明已经获取了access_token,还是不行,难道是我调用api的方式不对吗?
Ta的回复 :Eastonsoft: 我知道原因了,cuid要传appid,但是官方文档写的是Mac地址,坑爹啊。 回复Eastonsoft:为什么我改成了appid  和mac地址都还是显示3302错误呢?
14
authentication failed
Ta的回复 :mosal4hi: 服务已经恢复,看是否还复现? 回复mosal4hi:依然出现,cuid不管是改成appid还是mac地址都会报3302错误
7
原帖已删除
Ta的回复 :xie_yongkang: 回复xahef:您好, 为避免泄漏您的AK/SK删除了含有相关信息的代码, 后续也请注意不要对外泄露相关字段。对代码的其余部分进行了测试, 代码是正确的。建议在管理后台确认AK/SK是否正确, 相关应用的功能是否勾选, 谢谢。 回复xie_yongkang:请问后台的AK/SK在哪里管理
0
原帖已删除
Ta的回复 :xie_yongkang: 回复xahef:您好, 登录speech.baidu.com, 点击"应用管理" 回复xie_yongkang:点开了还是没看到。能截图告诉我吗,
0
原帖已删除
Ta的回复 :[图片]xie_yongkang: 回复xahef:您好, 登录speech.baidu.com, 点击"应用管理" 回复xie_yongkang:这个服务我我已经开通了啊
0
参数我都是对照者我的应用粘贴上去的啊,依然报错好像是501错
Ta的回复 :xie_yongkang: 您好, 请附上您的代码, 并注意屏蔽个人的AK/SK信息, 以便排查, 谢谢。 回复xie_yongkang: import java.io.BufferedReader; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.Scanner; import javax.xml.bind.DatatypeConverter; import org.json.JSONObject; public class SpeechSynthesis {     private  final String serverURL = "http://tsn.baidu.com/text2audio";     private  String token = "";     private  String text = "";     private  String saveURL = "";     private boolean isDetailed = false;     //pit6最好啦     private  int per = 0; //男1女0     private  int spd = 6; //音速0-9     private  int pit = 6; //音调0-9     private  int vol = 5; //音量0-9     //put your own params here     private   String apiKey = "";     private   String secretKey = "";     private   String cuid = "";     public SpeechSynthesis(String cuid){      this.cuid = cuid;      checkLocalToken();     }     public SpeechSynthesis(String apiKey , String secretKey , String cuid){            this.apiKey = apiKey;      this.secretKey = secretKey;      this.cuid = cuid;      checkLocalToken();     }     private void checkLocalToken() {  // TODO Auto-generated method stub    File tokenFile = new File("TTS_token.dat");       if(tokenFile.exists()){        try {      token = new Scanner(tokenFile).nextLine();     } catch (FileNotFoundException e) {      // TODO Auto-generated catch block      e.printStackTrace();     }       }       else{         try {         getToken();         PrintWriter output = new PrintWriter(tokenFile);         output.print(token);         output.close();        } catch (Exception e) {         // TODO Auto-generated catch block         System.out.println("获取认证失败,请检查apiKey,secreKey,cuid位置或者内容是否设置正确");         System.exit(1);        }       } }       //与验证服务器验证  获取token     public  void getToken() throws Exception {         String getTokenURL = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials" +             "&client_id=" + apiKey + "&client_secret=" + secretKey;         HttpURLConnection conn = (HttpURLConnection) new URL(getTokenURL).openConnection();   //与验证服务器连接         token = new JSONObject(printResponse(conn)).getString("access_token");//获取access_token:...后的taken     }            private  String printResponse(HttpURLConnection conn) throws Exception {         if (conn.getResponseCode() != 200) {             // request error            System.err.println("请求失败,请检查网络");            return "";         }         InputStream is = conn.getInputStream();         BufferedReader rd = new BufferedReader(new InputStreamReader(is));         String line;         StringBuffer response = new StringBuffer();         while ((line = rd.readLine()) != null) {             response.append(line);             response.append('\r');         }         rd.close();         if(isDetailed){          System.out.println( new JSONObject(response.toString()).toString(4));       }         return response.toString();     }       //把语音文件转换成byte数组存储        private  byte[] getData(HttpURLConnection conn) throws IOException {         InputStream is = conn.getInputStream();            ArrayList byteList = new ArrayList<>();            int value;         while((value = is.read()) != -1){  //读取流的技巧              byteList.add(value);                          }         //这里是一个冗余的方式                    byte[] bytes = new byte[byteList.size()];            int[] intbytes = new int[bytes.length];            for(int i = 0; i < bytes.length;i++){                 intbytes[i] = (int) byteList.get(i);               }            for(int i = 0; i < bytes.length;i++){          bytes[i] =(byte) intbytes[i];               }         is.close();         System.out.println("语音成功合成");         return bytes;     }         //利用获得的token与语音服务器连接     public  void methodByGET() throws Exception {       if(saveURL.isEmpty() || text.isEmpty()){       System.err.println("未识别语音保存位置 或者未设置发送内容");     System.exit(1);      }      HttpURLConnection conn = (HttpURLConnection) new URL(serverURL                 + "?tex=" + new String((text).getBytes(),"UTF-8") + "&lan=zh"  + "&cuid=" + cuid + "&ctp=1" + "&tok=" + token                 +"&per=" + per + "&spd=" + spd + "&pit=" + pit+ "&vol=" + vol).openConnection();         // add request header         conn.setRequestMethod("GET");         conn.setRequestProperty("Content-Type", "audio/mp3");         conn.setDoInput(true);         conn.setDoOutput(true);            //输出到指定目录         DataOutputStream out = new DataOutputStream(new FileOutputStream(saveURL));  //能保存为音频格式说明传递的就是音频本体 而不是html         out.write(getData(conn));     }     public void methodByGET(String text){      setText(text);         try {    methodByGET();   } catch (Exception e) {    // TODO Auto-generated catch block    e.printStackTrace();   }           }     public void setVoice(int speed , int pitch ,int volume){      setSpeed(speed);      setPitch(pitch);      setVolume(volume);     }     public void setSpeed(int speed){      if(speed > -1 && speed < 10)       this.spd = speed;      else {       System.err.println("大小范围0-9");       System.exit(1);      }     }     public void setPitch(int pitch){      if(pitch > -1 && pitch < 10)       this.pit = pitch;      else {       System.err.println("大小范围0-9");       System.exit(1);      }     }     public void setVolume(int volume){      if(volume > -1 && volume < 10 )       this.vol = volume;      else{       System.err.println("大小范围0-9");       System.exit(1);      }     }     public void changeSex(){      if(per == 0){       per = 1;      }else{       per = 0;      }     }     public void setIsDetailed(boolean isDetailed){      this.isDetailed = isDetailed;     }     public void setSaveURL(String path){      this.saveURL = path;     }     public void setText(String text){       StringBuffer textBuffer = new StringBuffer(text);       for(int i = 0 ; i < textBuffer.length();i++){        if(textBuffer.charAt(i) == ' '){         textBuffer.replace(i, i+1, ",");         }        }       this.text = textBuffer.toString();      }     public void setToken(String token){      this.token = token;     } }
5
语音合成提示参数错误
Ta的回复 :请问你有没有解决这个问题,如果已经解决了,能把代码给我吗?谢谢了
3
参数我都是对照者我的应用粘贴上去的啊,依然报错好像是501错
Ta的回复 :回复fujiayi1984:[图片]在控制台中无法获取那段结果
5
切换版块
智能客服