Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Lil synth changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lesterrry authored May 8, 2021
1 parent a477c2e commit a52b634
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
26 changes: 18 additions & 8 deletions SFX Processor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SFX {
}

public static func playSFX(sfx: Effects){
print(AVSpeechSynthesisVoice.speechVoices())
if let url = Bundle.main.url(forResource: sfx.rawValue, withExtension: "mp3", subdirectory: "SFX") {
do {
player = try AVAudioPlayer(contentsOf: url)
Expand All @@ -48,6 +49,7 @@ class SFX {
}

public static func speak(say: String, lang: String) {
testVoices()
let utterance = AVSpeechUtterance(string: say)
switch lang {
case "en":
Expand All @@ -66,6 +68,13 @@ class SFX {
}
}
utterance.voice = AVSpeechSynthesisVoice(identifier: voiceIdentifier!)
case "ru-RU":
let d = "com.apple.speech.synthesis.voice.milena.premium"
if AVSpeechSynthesisVoice(identifier: d) != nil {
utterance.voice = AVSpeechSynthesisVoice(identifier: d)
} else {
utterance.voice = AVSpeechSynthesisVoice(language: lang)
}
default:
utterance.voice = AVSpeechSynthesisVoice(language: lang)
}
Expand All @@ -78,11 +87,12 @@ class SFX {
}

public static func speakWelcome(){
speak(say: AutomneAxioms.specialWelcomeNarratives.randomElement()!, lang: "en")
speak(say: "Добрый день", lang: "ru-RU")
// speak(say: AutomneAxioms.specialWelcomeNarratives.randomElement()!, lang: "en")
}

public static func composeAndSpeak(track: String, artist: String) -> Bool {
if synth.isSpeaking { return false }
public static func composeAndSpeak(track: String, artist: String) -> (Bool, String?) {
if synth.isSpeaking { return (false, "already speaking") }
let a = Int.random(in: 1...8)
if a == 1 || a == 2 {
let s = AutomneAxioms.trackNarratives.randomElement()
Expand All @@ -91,7 +101,7 @@ class SFX {
let lang: String
if d.isLatin { lang = "en" }
else if d.isCyrillic { lang = "ru-RU" }
else { return false }
else { return (false, "difficult phrase: " + d) }
if s!.1 { speak(say: f, lang: "en") }
speak(say: d, lang: lang)
if !s!.1 { speak(say: f, lang: "en") }
Expand All @@ -114,7 +124,7 @@ class SFX {
case 20...23:
d = "evening"
default:
return false
return (false, "hour err")
}
s = AutomneAxioms.specialTimeNarratives[d]!.randomElement()!
}
Expand All @@ -123,11 +133,11 @@ class SFX {
} else if s.isCyrillic {
speak(say: s, lang: "ru-RU")
} else {
return false
return (false, "difficult phrase: " + s)
}
} else {
return false
return (false, "rnd case")
}
return true
return (true, nil)
}
}
6 changes: 5 additions & 1 deletion ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,14 @@ class ViewController: NSViewController{
ViewController.player.volume = 1.0

if ViewController.defaults.integer(forKey: "narrator") == 1 && !isStream {
if SFX.composeAndSpeak(track: (track!.title ?? "unknown"), artist: (track!.user?.username) ?? "unknown") {
let a = SFX.composeAndSpeak(track: (track!.title ?? "unknown"), artist: (track!.user?.username) ?? "unknown")
if a.0 {
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0, execute: { ViewController.player.play() })
} else {
ViewController.player.play()
if ViewController.defaults.integer(forKey: "verbose") == 1 {
tprint("WARN: (synth) \(a.1 ?? "nil")")
}
}
} else {
ViewController.player.play()
Expand Down

0 comments on commit a52b634

Please sign in to comment.