use of com.qiniu.storage.BucketManager in project symphony by b3log.
the class AudioMgmtService method tts.
/**
* Text to speech.
*
* @param text the specified text
* @param type specified type, "article"/"comment"
* @param textId the specified id of text, article id or comment id
* @param uid the specified user id
* @return speech URL, returns {@code ""} if TTS failed
*/
public String tts(final String text, final String type, final String textId, final String uid) {
final byte[] bytes = baiduTTS(text, uid);
if (null == bytes) {
return "";
}
String ret;
try {
if (Symphonys.getBoolean("qiniu.enabled")) {
final Auth auth = Auth.create(Symphonys.get("qiniu.accessKey"), Symphonys.get("qiniu.secretKey"));
final UploadManager uploadManager = new UploadManager(new Configuration());
final BucketManager bucketManager = new BucketManager(auth, new Configuration());
final int seq = RandomUtils.nextInt(10);
final String fileKey = "audio/" + type + "/" + textId + seq + ".mp3";
try {
bucketManager.delete(Symphonys.get("qiniu.bucket"), fileKey);
} catch (final Exception e) {
// ignore
}
uploadManager.put(bytes, fileKey, auth.uploadToken(Symphonys.get("qiniu.bucket")), null, "audio/mp3", false);
ret = Symphonys.get("qiniu.domain") + "/audio/" + type + "/" + textId + seq + ".mp3";
} else {
final String fileName = UUID.randomUUID().toString().replaceAll("-", "") + ".mp3";
final OutputStream output = new FileOutputStream(Symphonys.get("upload.dir") + fileName);
IOUtils.write(bytes, output);
IOUtils.closeQuietly(output);
ret = Latkes.getServePath() + "/upload/" + fileName;
}
return ret;
} catch (final Exception e) {
if (e instanceof QiniuException) {
try {
LOGGER.log(Level.ERROR, "Uploads audio failed [type=" + type + ", textId=" + textId + "], Qiniu exception body [" + ((QiniuException) e).response.bodyString() + "]");
} catch (final Exception qe) {
LOGGER.log(Level.ERROR, "Uploads audio and parse result exception", qe);
}
} else {
LOGGER.log(Level.ERROR, "Uploads audio failed [type=" + type + ", textId=" + textId + "]", e);
}
}
return "";
}
use of com.qiniu.storage.BucketManager in project paascloud-master by paascloud.
the class QiniuOssConfiguration method bucketManager.
/**
* Bucket manager bucket manager.
*
* @return the bucket manager
*/
@Bean
public BucketManager bucketManager() {
Zone zone = Zone.autoZone();
// 创建上传对象
BucketManager uploadManager = new BucketManager(auth(), new com.qiniu.storage.Configuration(zone));
log.info("Create BucketManager OK.");
return uploadManager;
}
Aggregations