语音合成,文字转语音,文字合成语音,最简单免费的方式,轻语API,uniapp开发全教学,轻语API 5555api.com

125 阅读2分钟

轻语Api官网

语音合成、文字生成语音、文字转语音、配音,目前是长期免费的,不要一分钱,但因有服务器等费用支出,后续会收取一定微薄费用,后续即使收费也将以非常低廉的价格面对开发者,承诺永远不会高于任何一个平台,可收藏关注5555api.com轻语官网。

- V1版本语言合成接口

5555api.com/data/api/fe… POST

接口参数:

  1. apikey 固定值 ”test_app_key_5555api.com“【必填】

  2. text 要合成语音的文字内容【必填】

V2版本语音合成接口

5555api.com/data/api/fe… POST

V2版本支持自选发音人,可选设置音调、音量、音率参数

参数:

  1. apikey 固定值 ”test_app_key_5555api.com“【必填】

  2. text 要合成语音的文字内容【必填】

  3. role 发音人,发音的角色,可选值"国语|女|颜颜", "国语|女|悦悦","国语|男|小明","国语|男|小强","国语|男|小刚","方言|女|宁宁","方言|女|贝贝","港语|女|嘉嘉","港语|女|蕊蕊","港语|男|小郎","台语|女|思思","台语|女|玲玲","台语|男|小冬",直接传字符串,更多角色请参阅5555api.com 官网。

  4. rate 音率

  5. pitch 音调

  6. volume 音量

下面是基于V2版本 uniapp的请求,V1版本修改链接以及参数即可

<template>
	<view>
		<view style="margin-bottom: 60rpx;margin-left: 20rpx;font-size: 26rpx;color: #999;">
			<view>1.输入文字</view>
			<view>2.点击生成语音</view>
			<view>3.生成后点击播放语音即可预览你的生成的语音</view>
		</view>
		
		<input v-model="text" placeholder="请输入要生成语音的文字" class="input_style" />
		<view @click="requestAPI" class="btn">生成语音</view>
		
		<view class="roles">
			<view v-for="(ro, rid) in roleList" v-bind:key="rid" class="role" :class="role == ro ? 'press':'normal'" @click="onSwitchRole(ro)">
				{{ro}}
			</view>
		</view>
		
		<view class="tip">语速、语音、语调等配置请参阅 https://5555api.com</view>
		
		<!-- <view v-if="resp" class="resp">{{resp}}</view> -->
		<view v-if="url && status==='no'" class="btn" @click="playVoice">播放语音</view>
		<view v-if="url && status==='no'" class="btn" @click="copyUrl">复制语音文件下载链接</view>
		<view v-else-if="status==='loading'" style="margin-top: 50rpx;">
			<image src="/static/icon_spinner.png" style="width: 68rpx;height: 68rpx;" class="rotating-element"></image>
		</view>
	</view>
</template>

<script>
	// 语音播放器实例
	let mp3 = uni.createInnerAudioContext();
	
	export default {
		data() {
			return {
				roleList: ["国语|女|颜颜", "国语|女|悦悦","国语|男|小明","国语|男|小强","国语|男|小刚","方言|女|宁宁","方言|女|贝贝","港语|女|嘉嘉","港语|女|蕊蕊","港语|男|小郎","台语|女|思思","台语|女|玲玲","台语|男|小冬"],
				role:'国语|女|颜颜',
				rate: 'normal',
				volume: 'normal',
				pitch: 'normal',
				text:'',
				status: 'none',
				url: '',
			}
		},
		methods: {
			onSwitchRole(role){
				this.role = role;
			},
			copyUrl(){
				uni.setClipboardData({
					data: this.url,
					success() {
						uni.showToast({
							title:'链接复制成功',
							icon:'none'
						});
					}
				})
			},	
			playVoice(){
				mp3.src = this.url;
				mp3.play();
			},
			requestAPI(){
				if(!this.text || this.text.length < 1){
					uni.showToast({
						title:'请输入内容',
						icon:'none'
					})
					return;
				}
				
				let that = this;
				that.status = 'loading';
				
				uni.request({
					method:'POST',
					url:'https://5555api.com/data/api/fetchVoiceByText_v2',
					// url:'http://192.168.10.106:9093/data/api/fetchVoiceByText_v2',
					data:{
						apikey: 'test_app_key_5555api.com',
						text: that.text,
						role: that.role
					},
					success(res) {
						that.status = 'no';
						console.error('请求成功:', res);
						that.url = res.data.data.url;
					},
					fail() {
						that.status = 'no';
					}
				});
			}
		}
	}
</script>

<style>
	.input_style{
		width: 600rpx;
		margin-left: 74rpx;
		margin-right: 75rpx;
		border: 2rpx solid #12c212;
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
		font-size: 28rpx;
		margin-top: 50rpx;
	}
	
	.btn{
		background-color: #12c212;
		color: #ffffff;
		display: flex;
		width: 450rpx;
		margin-left: 150rpx;
		margin-right: 149rpx;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		padding: 20rpx 0rpx;
		margin-top: 50rpx;
	}
	.tip{
	font-size: 24rpx; color: seagreen;margin-top: 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.roles{
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
	flex-wrap: wrap;
	margin-top: 20rpx;
}
.role{
	border-radius: 6rpx;
	padding: 2rpx 10rpx;
	font-size: 26rpx;
	margin: 5rpx;
}
.press{
	color: #fff;
	background-color: #ecb50f;
}
.normal{
	color: #999;
	background-color: #f8e6ae;
}
</style>

在这里插入图片描述