更新记录
v1(2024-02-26)
下载此版本
文字转语音
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 4.0 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
前端直接引入 tts
<script setup lang="ts">
import { playVoice } from '@/utils/voice.js'
import { getParams } from '@/utils/tts.js'
import { ref } from 'vue';
const title = ref<any>('测试')
const form = ref<any>({})
const handleAction = () => {
const url = getParams(form.value.text)
uni.request({
url: 'https://admin.net561.com/uniapp/tts/getSound',
method: 'GET',
data: { url },
success: ({ data: { data: { url } } }) => {
playVoice(url)
},
fail: () => { },
complete: () => { }
});
}
</script>
服务器端代码
function getSound($url)
$_result=file_get_contents($url);
$result=json_decode($_result,true);
$this->success('',['url'=>$result['data']]);
}
把转化后的语音文件返回给前端直接播放