Animalese-Swift

1.0.0

Swift library that synthesizes an approximation of the villager speech sounds from Animal Crossing. Port of https://github.com/Acedio/animalese.js
jakubpetrik/animalese-swift

What's New

Initial Release

2020-04-14T07:34:55Z

Animalese-Swift

platform SwiftPM-compatible

A Swift port of https://github.com/Acedio/animalese.js.

Usage

import SwiftUI
import AVFoundation
import Animalese_Swift

struct ContentView: View {
    @State var text = "Well, I do have a little musical knowledge..."
    @State var pitch = 1.0
    @State var shortenWords = false
    @State var player: AVAudioPlayer!

    private let synth = Animalese(
        letterLibrary: NSDataAsset(name: "animalese")!.data,
        sampleRate: 44100,
        libraryLetterSeconds: 0.15,
        outputLetterSeconds: 0.075
    )

    var body: some View {
        NavigationView {
            Form {
                TextField("Type here...", text: $text)
                Slider(value: $pitch, in: 0.2...2.0, step: 0.1, minimumValueLabel: Text("😡"), maximumValueLabel: Text("🐹")) {
                    Text("Pitch")
                }
                Toggle(isOn: $shortenWords) {
                    Text("Words shortening")
                }
                Button(action: play) {
                    Text("Play")
                }
            }.navigationBarTitle(Text("Animalese-Swift Demo"))
        }
    }

    func play() {
        let data = synth.synthesize(text, shortenWords: shortenWords, pitch: pitch)
        player = try! AVAudioPlayer(data: data)
        player.play()
    }
}

Installation

Swift Package Manager

Animalese-Swift is SwiftPM-compatible. To install, add this package to your Package.swift or your Xcode project.

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 04:56:22 GMT-0900 (Hawaii-Aleutian Daylight Time)