97 lines
2.1 KiB
C#
97 lines
2.1 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
public class TextToSpeekPanel : MonoBehaviour
|
|
{
|
|
public int speed;
|
|
public string tone;
|
|
|
|
public Text text;
|
|
public Button newPlayBtn;
|
|
public Button closeBtn;
|
|
public Button pusBtn;
|
|
public Button goOnBtn;
|
|
public Button playBtn;
|
|
public AudioSource _audioSource;
|
|
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="_text"></param>
|
|
/// <param name="_tone"></param>
|
|
/// <param name="_speed"></param>
|
|
public void Init(string _text, string _tone, int _speed)
|
|
{
|
|
|
|
text.text = _text;
|
|
speed = _speed;
|
|
tone = _tone;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
playBtn.onClick.AddListener(Play);
|
|
closeBtn.onClick.AddListener(ClosePanel);
|
|
newPlayBtn.onClick.AddListener(NewPlay);
|
|
pusBtn.onClick.AddListener(Pause);
|
|
goOnBtn.onClick.AddListener(GoOnPlay);
|
|
}
|
|
void GoOnPlay()
|
|
{
|
|
|
|
}
|
|
void Pause()
|
|
{
|
|
|
|
}
|
|
private void NewPlay()
|
|
{
|
|
_audioSource.Play();
|
|
}
|
|
/*
|
|
void PlayTextAudio(AudioClip Audio)
|
|
{
|
|
ConsolePanel.ConsoleOutput("开始播放语音", "log");
|
|
_audioSource.clip = Audio;
|
|
_audioSource.pitch = speed;
|
|
_audioSource.Play();
|
|
|
|
}
|
|
*/
|
|
/// <summary>
|
|
/// 不显示直接播放
|
|
/// </summary>
|
|
/// <param name="_text"></param>
|
|
/// <param name="_tone"></param>
|
|
/// <param name="_speed"></param>
|
|
public void PlayWithoutShow(string _text, string _tone, int _speed,AudioSource audioSource)
|
|
{
|
|
_audioSource = audioSource;
|
|
text.text = _text;
|
|
speed = _speed;
|
|
tone = _tone;
|
|
Play();
|
|
}
|
|
void Play()
|
|
{
|
|
ConsolePanel.ConsoleOutput("开始语音合成", "log");
|
|
IFlytekManager.instance.TextToAudio(text.text);
|
|
}
|
|
void ClosePanel()
|
|
{
|
|
_audioSource.Stop();
|
|
gameObject.SetActive(false);
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|