#!/usr/bin/env swift
import AVFoundation
// Create an utterance.
let utterance = AVSpeechUtterance(string: "The quick brown fox jumped over the lazy dog.")
// Configure the utterance.
utterance.rate = 0.57
utterance.pitchMultiplier = 0.8
utterance.postUtteranceDelay = 0.2
utterance.volume = 0.8
// Retrieve the British English voice.
let voice = AVSpeechSynthesisVoice(language: "en-GB")
// Assign the voice to the utterance.
utterance.voice = voice
// Create a speech synthesizer.
let synthesizer = AVSpeechSynthesizer()
// Tell the synthesizer to speak the utterance.
synthesizer.speak(utterance)
synthesizer.speak(AVSpeechUtterance(string: "Hello The quick brown fox jumped over the lazy dog."))
var myString = "Hello, World!"
print(myString)
为啥这个没有声音,synthesizer 不能用 swsh 脚本使用? 我是纯小白,也没学过 swift 今天发现 mac 的朗读功能挺有意思的就想调一下这个接口玩玩,但是发现没动静 感觉我的语法没问题啊,应该是 使用姿势不对吧,求指点要怎么用
目前就是想这个 出声音,求解
1
butanediol2d 2022-10-06 13:43:49 +08:00
你在最后加一个 sleep 试一下,可能是还没等开口说话程序就退出了。
|