add TencentTTS
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
import SwiftUI
|
||||
import AVFoundation
|
||||
import ToastUI
|
||||
import FirebaseAnalytics
|
||||
|
||||
struct SubmitTextEditor: UIViewRepresentable {
|
||||
@Binding var text: String
|
||||
@ -271,7 +272,9 @@ struct TranslateCardView: View {
|
||||
var onEdit: (String) -> Void
|
||||
var onCopy: (String) -> Void
|
||||
var onFeedback: (TranslateFeedback) -> Void
|
||||
let synthesizer = AVSpeechSynthesizer()
|
||||
|
||||
// 创建委托类的实例
|
||||
@State private var isSynthesizing = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
@ -285,15 +288,15 @@ struct TranslateCardView: View {
|
||||
Text(translation.input)
|
||||
.padding(.bottom, 3)
|
||||
HStack {
|
||||
/*
|
||||
|
||||
Button(action: {
|
||||
speakText(translation.input)
|
||||
synthesizeAndPlay(text: translation.input, lang: "Original")
|
||||
}) {
|
||||
Image(systemName: "speaker.wave.2")
|
||||
.foregroundColor(.blue)
|
||||
.padding(.trailing)
|
||||
}
|
||||
*/
|
||||
|
||||
Spacer()
|
||||
Button(action: {
|
||||
onEdit(translation.input)
|
||||
@ -315,14 +318,14 @@ struct TranslateCardView: View {
|
||||
.padding(.vertical, 1) // 减少与分割线的间距
|
||||
.padding(.bottom, 3) // 减少与原文之间的间距
|
||||
HStack {
|
||||
/*
|
||||
|
||||
Button(action: {
|
||||
speakText(translation.translation)
|
||||
synthesizeAndPlay(text: translation.translation, lang: "Translated")
|
||||
}) {
|
||||
Image(systemName: "speaker.wave.2")
|
||||
.foregroundColor(.blue)
|
||||
}
|
||||
*/
|
||||
|
||||
Spacer()
|
||||
HStack(spacing: 15) {// 减小图标之间的间距
|
||||
Button(action: {
|
||||
@ -362,14 +365,27 @@ struct TranslateCardView: View {
|
||||
.background(Color.gray.opacity(0.2)) // 设置整个卡片的背景色为LightGray
|
||||
.overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.gray, lineWidth: 1))
|
||||
}
|
||||
|
||||
func speakText(_ text: String) {
|
||||
let utterance = AVSpeechUtterance(string: text)
|
||||
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
|
||||
synthesizer.speak(utterance)
|
||||
|
||||
func synthesizeAndPlay(text: String, lang: String) {
|
||||
// 记录事件
|
||||
Analytics.logEvent("TTSClick", parameters: [
|
||||
"vendor": "TencentTTS",
|
||||
"lang" : lang
|
||||
])
|
||||
|
||||
isSynthesizing = true
|
||||
TTSManager.shared.synthesizeAndPlay(text: text, isVIP: globalEnvironment.isVip, onSuccess: {
|
||||
isSynthesizing = false
|
||||
logger.info("Synthesis succ.")
|
||||
}, onFailure: { error in
|
||||
isSynthesizing = false
|
||||
logger.info("Synthesis error: \(error)")
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extension View {
|
||||
func dashed() -> some View {
|
||||
self.overlay(
|
||||
|
||||
Reference in New Issue
Block a user