我目前是用自己的服务器中转了下,Python代码如下:
def convert_silk_to_mp3():
url = request.args.get('url')
import shutil
import os
import leancloud
filename = url.split('/')[-1]
download_path = '/tmp/' + filename
r = requests.get(url, stream=True)
if r.status_code == 200:
with open(download_path, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
os.system("sh /usr/share/silk-v3-decoder-master/converter.sh " + download_path + " mp3")
convert_path = '/tmp/' + filename + '.mp3'
with open(convert_path) as f:
voice = leancloud.File('weapp-voice-' + filename + '.mp3', f)
voice.save()
return {'id': voice.id, 'url': voice.url}
先从 leancloud 把 slk 文件下载下来,然后本地用 ffmpeg 转化,然后再上传到 leancloud。
比较迂回...如果云引擎上可以做,就可以省掉2次网络传输的时间。