ElevenLabs Voice
Text-to-speech component using ElevenLabs API

Preview

Code
1import SwiftUI2import AVFoundation34struct VoiceSynthesizerView: View {5 @State private var text = "Hello, this is a sample text for voice synthesis."6 @State private var isPlaying = false7 @State private var selectedVoice = "Rachel"8 @State private var speechRate: Float = 0.59 10 let voices = ["Rachel", "Drew", "Clyde", "Paul", "Domi"]11 12 var body: some View {13 VStack(spacing: 24) {14 VStack(alignment: .leading, spacing: 12) {15 Text("ElevenLabs Voice Synthesis")16 .font(.title2)17 .fontWeight(.semibold)18 19 Text("Convert text to natural speech")20 .font(.caption)21 .foregroundColor(.secondary)22 }23 24 VStack(spacing: 16) {25 TextField("Enter text to synthesize", text: $text, axis: .vertical)26 .textFieldStyle(.roundedBorder)27 .lineLimit(4...8)28 29 HStack {30 Text("Voice:")31 Picker("Voice", selection: $selectedVoice) {32 ForEach(voices, id: \.self) { voice in33 Text(voice).tag(voice)34 }35 }36 .pickerStyle(.menu)37 Spacer()38 }39 40 VStack(alignment: .leading) {41 Text("Speech Rate: \(speechRate, specifier: "%.1f")")42 Slider(value: $speechRate, in: 0.1...1.0)43 }44 }45 46 Button(action: {47 togglePlayback()48 }) {49 HStack {50 Image(systemName: isPlaying ? "stop.fill" : "play.fill")51 Text(isPlaying ? "Stop" : "Play")52 }53 .frame(maxWidth: .infinity)54 .padding()55 .background(isPlaying ? Color.red : Color.blue)56 .foregroundColor(.white)57 .cornerRadius(8)58 }59 }60 .padding(24)61 .background(Color(.systemBackground))62 .cornerRadius(16)63 .shadow(radius: 8)64 }65 66 func togglePlayback() {67 isPlaying.toggle()68 // ElevenLabs API integration here69 }70}7172struct VoiceSynthesizerView_Previews: PreviewProvider {73 static var previews: some View {74 VoiceSynthesizerView()75 }76}