import SwiftUI
import AVFoundation

struct ContentView: View {
   @State private var appData = ApplicationData.shared
   @State private var text: String = ""

   var body: some View {
      VStack {
         TextField("Input text", text: $text)
            .textFieldStyle(.roundedBorder)
         HStack {
            Picker("", selection: $appData.selectedVoice) {
               ForEach(appData.listVoices, id: \.self) { voice in
                  Text(voice.name)
                     .tag(voice.identifier)
               }
            }
            Button("Talk") {
               if !text.isEmpty {
                  appData.say(text: text)
               }
            }
            .buttonStyle(.borderedProminent)
         }
         .padding()
         Spacer()
      }
      .padding()
   }
}