File size: 1,898 Bytes
1dfb01c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ed6654
 
 
1dfb01c
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Foundation

/// Configuration constants for the Plapre Pico TTS pipeline.
/// These values are fixed by the model architecture and must match the converted CoreML models.
enum PlapreConfig {
    // MARK: - Audio Parameters
    static let sampleRate = 24_000
    static let audioTokensPerSecond = 25

    // MARK: - Model Architecture
    static let vocabSize = 20_802
    static let maxContextLength = 512
    static let prefillSequenceLength = 512
    static let hiddenDimension = 576
    static let headDimension = 64
    static let numKVHeads = 3
    static let speakerEmbeddingDimension = 128

    // MARK: - Token Ranges
    static let eosToken: Int32 = 0
    static let textMarkerToken: Int32 = 8_000
    static let audioMarkerToken: Int32 = 8_001
    static let audioTokenOffset = 8_002
    static let audioTokenMax = 20_801

    // MARK: - Inference Parameters
    static let defaultTemperature: Float = 0.8
    static let defaultTopK = 50
    static let maxGenerationTokens = 500
    static let nonAudioStopThreshold = 10

    // MARK: - Vocoder Parameters
    static let kanadeChunkSize = 100  // 4 seconds at 25 tok/s

    // MARK: - Paths
    /// Computes the repository root directory from the current source file location.
    /// Traverses: Sources → swift-cli → repo root
    static var repoRoot: URL {
        URL(fileURLWithPath: #filePath)
            .deletingLastPathComponent()  // Sources
            .deletingLastPathComponent()  // swift-cli
            .deletingLastPathComponent()  // repo root
    }

    /// Returns the URL for a model package, accounting for quantization flags.
    static func modelURL(for name: String, useInt8: Bool) -> URL {
        if name == "PlaprePico" && useInt8 {
            return repoRoot.appendingPathComponent("PlaprePico_int8.mlpackage")
        }
        return repoRoot.appendingPathComponent("\(name).mlpackage")
    }
}