ios开发: hello,world

一,代码:

import SwiftUI
import AVFoundation

struct ContentView: View {
    
    let synthesizer = AVSpeechSynthesizer()
    
    var body: some View {
        Button {
            let utter = AVSpeechUtterance(string: "hello,world")
            utter.voice = AVSpeechSynthesisVoice(identifier: "com.apple.speech.synthesis.voice.Fred")
            synthesizer.speak(utter)
        } label:{
            Text("点击抽奖")
                .fontWeight(.bold)
                .font(.system(.title, design: .rounded))
        }
        .padding()
        .foregroundStyle(.white)
        .background(.purple)
        .clipShape(RoundedRectangle(cornerRadius: 20))
    }
}

#Preview {
    ContentView()
}

二,效果:

image

posted @ 2026-03-28 15:50  刘宏缔的架构森林  阅读(1)  评论(0)    收藏  举报