Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more
Add tests for transcription
grohith327dca51e9aea78
diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 36d745c5..97df28a3 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -14,7 +14,7 @@ jobs:build:name: Build FluidVoiceruns-on: macos-latest- timeout-minutes: 20+ timeout-minutes: 40steps:- name: Checkout code@@ -23,6 +23,15 @@ jobs:- name: Install SwiftLintrun: brew install swiftlint+ - name: Install xcpretty+ run: sudo gem install xcpretty++ - name: Cache Whisper models+ uses: actions/cache@v4+ with:+ path: ~/Library/Caches/WhisperModels+ key: ${{ runner.os }}-whisper-models-v1+- name: Run SwiftLint (strict)run: swiftlint --strict --config .swiftlint.yml@@ -50,7 +59,7 @@ jobs:| xcprettycontinue-on-error: false- - name: Run Tests (if available)+ - name: Run Testsrun: |set -o pipefailxcodebuild test \@@ -59,5 +68,5 @@ jobs:-destination 'platform=macOS,arch=arm64' \CODE_SIGN_IDENTITY="" \CODE_SIGNING_REQUIRED=NO \- | xcpretty- continue-on-error: true # Don't fail if no tests exist\ No newline at end of file+ CODE_SIGNING_ALLOWED=NO \+ | xcpretty\ No newline at end of filediff --git a/Fluid.xcodeproj/project.pbxproj b/Fluid.xcodeproj/project.pbxprojindex 42b8403b..f980da4e 100644--- a/Fluid.xcodeproj/project.pbxproj+++ b/Fluid.xcodeproj/project.pbxproj@@ -12,10 +12,29 @@7C3236542EAAD608007E4CB6 /* MCP in Frameworks */ = {isa = PBXBuildFile; productRef = 7C3236532EAAD608007E4CB6 /* MCP */; };7C3697892ED70F9C005874CE /* DynamicNotchKit in Frameworks */ = {isa = PBXBuildFile; productRef = 7C3697882ED70F9C005874CE /* DynamicNotchKit */; };7CE006BD2E80EBE600DDCCD6 /* AppUpdater in Frameworks */ = {isa = PBXBuildFile; productRef = 7CE006BC2E80EBE600DDCCD6 /* AppUpdater */; };+ 7CDB0A2D2F3C4D5600FB7CAD /* DictationE2ETests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CDB0A292F3C4D5600FB7CAD /* DictationE2ETests.swift */; };+ 7CDB0A2E2F3C4D5600FB7CAD /* AudioFixtureLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CDB0A2A2F3C4D5600FB7CAD /* AudioFixtureLoader.swift */; };+ 7CDB0A2F2F3C4D5600FB7CAD /* dictation_fixture.wav in Resources */ = {isa = PBXBuildFile; fileRef = 7CDB0A2B2F3C4D5600FB7CAD /* dictation_fixture.wav */; };+ 7CDB0A302F3C4D5600FB7CAD /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7CDB0A2C2F3C4D5600FB7CAD /* XCTest.framework */; };/* End PBXBuildFile section */+/* Begin PBXContainerItemProxy section */+ 7CDB0A322F3C4D5600FB7CAD /* PBXContainerItemProxy */ = {+ isa = PBXContainerItemProxy;+ containerPortal = 7C078D872E3B339200FB7CAC /* Project object */;+ proxyType = 1;+ remoteGlobalIDString = 7C078D8E2E3B339200FB7CAC;+ remoteInfo = fluid;+ };+/* End PBXContainerItemProxy section */+/* Begin PBXFileReference section */7C078D8F2E3B339200FB7CAC /* FluidVoice Debug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FluidVoice Debug.app"; sourceTree = BUILT_PRODUCTS_DIR; };+ 7CDB0A202F3C4D5600FB7CAD /* FluidDictationIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FluidDictationIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };+ 7CDB0A292F3C4D5600FB7CAD /* DictationE2ETests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DictationE2ETests.swift; sourceTree = "<group>"; };+ 7CDB0A2A2F3C4D5600FB7CAD /* AudioFixtureLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioFixtureLoader.swift; sourceTree = "<group>"; };+ 7CDB0A2B2F3C4D5600FB7CAD /* dictation_fixture.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = dictation_fixture.wav; sourceTree = "<group>"; };+ 7CDB0A2C2F3C4D5600FB7CAD /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };/* End PBXFileReference section *//* Begin PBXFileSystemSynchronizedRootGroup section */@@ -39,6 +58,14 @@);runOnlyForDeploymentPostprocessing = 0;};+ 7CDB0A222F3C4D5600FB7CAD /* Frameworks */ = {+ isa = PBXFrameworksBuildPhase;+ buildActionMask = 2147483647;+ files = (+ 7CDB0A302F3C4D5600FB7CAD /* XCTest.framework in Frameworks */,+ );+ runOnlyForDeploymentPostprocessing = 0;+ };/* End PBXFrameworksBuildPhase section *//* Begin PBXGroup section */@@ -46,13 +73,58 @@isa = PBXGroup;children = (7C078D912E3B339200FB7CAC /* Sources/Fluid */,+ 7CDB0A242F3C4D5600FB7CAD /* Tests */,+ 7CDB0A282F3C4D5600FB7CAD /* Frameworks */,+ );+ sourceTree = "<group>";+ };+ 7CDB0A242F3C4D5600FB7CAD /* Tests */ = {+ isa = PBXGroup;+ children = (+ 7CDB0A252F3C4D5600FB7CAD /* FluidDictationIntegrationTests */,);+ path = Tests;+ sourceTree = "<group>";+ };+ 7CDB0A252F3C4D5600FB7CAD /* FluidDictationIntegrationTests */ = {+ isa = PBXGroup;+ children = (+ 7CDB0A262F3C4D5600FB7CAD /* Helpers */,+ 7CDB0A272F3C4D5600FB7CAD /* Resources */,+ 7CDB0A292F3C4D5600FB7CAD /* DictationE2ETests.swift */,+ );+ path = FluidDictationIntegrationTests;+ sourceTree = "<group>";+ };+ 7CDB0A262F3C4D5600FB7CAD /* Helpers */ = {+ isa = PBXGroup;+ children = (+ 7CDB0A2A2F3C4D5600FB7CAD /* AudioFixtureLoader.swift */,+ );+ path = Helpers;+ sourceTree = "<group>";+ };+ 7CDB0A272F3C4D5600FB7CAD /* Resources */ = {+ isa = PBXGroup;+ children = (+ 7CDB0A2B2F3C4D5600FB7CAD /* dictation_fixture.wav */,+ );+ path = Resources;+ sourceTree = "<group>";+ };+ 7CDB0A282F3C4D5600FB7CAD /* Frameworks */ = {+ isa = PBXGroup;+ children = (+ 7CDB0A2C2F3C4D5600FB7CAD /* XCTest.framework */,+ );+ name = Frameworks;sourceTree = "<group>";};7C078D902E3B339200FB7CAC /* Products */ = {isa = PBXGroup;children = (7C078D8F2E3B339200FB7CAC /* FluidVoice Debug.app */,+ 7CDB0A202F3C4D5600FB7CAD /* FluidDictationIntegrationTests.xctest */,);name = Products;sourceTree = "<group>";@@ -87,6 +159,24 @@productReference = 7C078D8F2E3B339200FB7CAC /* FluidVoice Debug.app */;productType = "com.apple.product-type.application";};+ 7CDB0A1F2F3C4D5600FB7CAD /* FluidDictationIntegrationTests */ = {+ isa = PBXNativeTarget;+ buildConfigurationList = 7CDB0A332F3C4D5600FB7CAD /* Build configuration list for PBXNativeTarget "FluidDictationIntegrationTests" */;+ buildPhases = (+ 7CDB0A212F3C4D5600FB7CAD /* Sources */,+ 7CDB0A222F3C4D5600FB7CAD /* Frameworks */,+ 7CDB0A232F3C4D5600FB7CAD /* Resources */,+ );+ buildRules = (+ );+ dependencies = (+ 7CDB0A312F3C4D5600FB7CAD /* PBXTargetDependency */,+ );+ name = FluidDictationIntegrationTests;+ productName = FluidDictationIntegrationTests;+ productReference = 7CDB0A202F3C4D5600FB7CAD /* FluidDictationIntegrationTests.xctest */;+ productType = "com.apple.product-type.bundle.unit-test";+ };/* End PBXNativeTarget section *//* Begin PBXProject section */@@ -100,6 +190,9 @@7C078D8E2E3B339200FB7CAC = {CreatedOnToolsVersion = 26.0;};+ 7CDB0A1F2F3C4D5600FB7CAD = {+ CreatedOnToolsVersion = 26.0;+ };};};buildConfigurationList = 7C078D8A2E3B339200FB7CAC /* Build configuration list for PBXProject "Fluid" */;@@ -124,6 +217,7 @@projectRoot = "";targets = (7C078D8E2E3B339200FB7CAC /* fluid */,+ 7CDB0A1F2F3C4D5600FB7CAD /* FluidDictationIntegrationTests */,);};/* End PBXProject section */@@ -136,6 +230,14 @@);runOnlyForDeploymentPostprocessing = 0;};+ 7CDB0A232F3C4D5600FB7CAD /* Resources */ = {+ isa = PBXResourcesBuildPhase;+ buildActionMask = 2147483647;+ files = (+ 7CDB0A2F2F3C4D5600FB7CAD /* dictation_fixture.wav in Resources */,+ );+ runOnlyForDeploymentPostprocessing = 0;+ };/* End PBXResourcesBuildPhase section *//* Begin PBXSourcesBuildPhase section */@@ -146,8 +248,25 @@);runOnlyForDeploymentPostprocessing = 0;};+ 7CDB0A212F3C4D5600FB7CAD /* Sources */ = {+ isa = PBXSourcesBuildPhase;+ buildActionMask = 2147483647;+ files = (+ 7CDB0A2E2F3C4D5600FB7CAD /* AudioFixtureLoader.swift in Sources */,+ 7CDB0A2D2F3C4D5600FB7CAD /* DictationE2ETests.swift in Sources */,+ );+ runOnlyForDeploymentPostprocessing = 0;+ };/* End PBXSourcesBuildPhase section */+/* Begin PBXTargetDependency section */+ 7CDB0A312F3C4D5600FB7CAD /* PBXTargetDependency */ = {+ isa = PBXTargetDependency;+ target = 7C078D8E2E3B339200FB7CAC /* fluid */;+ targetProxy = 7CDB0A322F3C4D5600FB7CAD /* PBXContainerItemProxy */;+ };+/* End PBXTargetDependency section */+/* Begin XCBuildConfiguration section */7C078D982E3B339300FB7CAC /* Debug */ = {isa = XCBuildConfiguration;@@ -382,6 +501,55 @@};name = Release;};+ 7CDB0A342F3C4D5600FB7CAD /* Debug */ = {+ isa = XCBuildConfiguration;+ buildSettings = {+ ALWAYS_SEARCH_USER_PATHS = NO;+ ARCHS = "$(ARCHS_STANDARD)";+ BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/FluidVoice Debug.app/Contents/MacOS/FluidVoice Debug";+ CLANG_ENABLE_MODULES = YES;+ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";+ CODE_SIGN_STYLE = Automatic;+ DEVELOPMENT_TEAM = J67LH9U7BN;+ GENERATE_INFOPLIST_FILE = YES;+ INFOPLIST_KEY_CFBundleDisplayName = FluidDictationIntegrationTests;+ LD_RUNPATH_SEARCH_PATHS = (+ "$(inherited)",+ "@executable_path/../Frameworks",+ );+ MACOSX_DEPLOYMENT_TARGET = 14.0;+ PRODUCT_BUNDLE_IDENTIFIER = com.FluidApp.FluidDictationIntegrationTests;+ PRODUCT_NAME = FluidDictationIntegrationTests;+ SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";+ SWIFT_VERSION = 5.0;+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FluidVoice Debug.app/Contents/MacOS/FluidVoice Debug";+ };+ name = Debug;+ };+ 7CDB0A352F3C4D5600FB7CAD /* Release */ = {+ isa = XCBuildConfiguration;+ buildSettings = {+ ALWAYS_SEARCH_USER_PATHS = NO;+ ARCHS = "$(ARCHS_STANDARD)";+ BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/FluidVoice.app/Contents/MacOS/FluidVoice";+ CLANG_ENABLE_MODULES = YES;+ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";+ CODE_SIGN_STYLE = Automatic;+ DEVELOPMENT_TEAM = J67LH9U7BN;+ GENERATE_INFOPLIST_FILE = YES;+ INFOPLIST_KEY_CFBundleDisplayName = FluidDictationIntegrationTests;+ LD_RUNPATH_SEARCH_PATHS = (+ "$(inherited)",+ "@executable_path/../Frameworks",+ );+ MACOSX_DEPLOYMENT_TARGET = 14.0;+ PRODUCT_BUNDLE_IDENTIFIER = com.FluidApp.FluidDictationIntegrationTests;+ PRODUCT_NAME = FluidDictationIntegrationTests;+ SWIFT_VERSION = 5.0;+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FluidVoice.app/Contents/MacOS/FluidVoice";+ };+ name = Release;+ };/* End XCBuildConfiguration section *//* Begin XCConfigurationList section */@@ -403,6 +571,15 @@defaultConfigurationIsVisible = 0;defaultConfigurationName = Release;};+ 7CDB0A332F3C4D5600FB7CAD /* Build configuration list for PBXNativeTarget "FluidDictationIntegrationTests" */ = {+ isa = XCConfigurationList;+ buildConfigurations = (+ 7CDB0A342F3C4D5600FB7CAD /* Debug */,+ 7CDB0A352F3C4D5600FB7CAD /* Release */,+ );+ defaultConfigurationIsVisible = 0;+ defaultConfigurationName = Release;+ };/* End XCConfigurationList section *//* Begin XCRemoteSwiftPackageReference section */diff --git a/Fluid.xcodeproj/xcshareddata/xcschemes/Fluid.xcscheme b/Fluid.xcodeproj/xcshareddata/xcschemes/Fluid.xcschemeindex 93b13239..be14e83b 100644--- a/Fluid.xcodeproj/xcshareddata/xcschemes/Fluid.xcscheme+++ b/Fluid.xcodeproj/xcshareddata/xcschemes/Fluid.xcscheme@@ -29,6 +29,18 @@selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"shouldUseLaunchSchemeArgsEnv = "YES"shouldAutocreateTestPlan = "YES">+ <Testables>+ <TestableReference+ skipped = "NO">+ <BuildableReference+ BuildableIdentifier = "primary"+ BlueprintIdentifier = "7CDB0A1F2F3C4D5600FB7CAD"+ BuildableName = "FluidDictationIntegrationTests.xctest"+ BlueprintName = "FluidDictationIntegrationTests"+ ReferencedContainer = "container:Fluid.xcodeproj">+ </BuildableReference>+ </TestableReference>+ </Testables></TestAction><LaunchActionbuildConfiguration = "Release"diff --git a/README.md b/README.mdindex 6523d92f..f102852c 100644--- a/README.md+++ b/README.md@@ -146,6 +146,24 @@ Contributions are welcome! Please create an issue first to discuss any major chaFollow development updates on X: [@ALTIC_DEV](https://x.com/ALTIC_DEV)+## Run integration dictation test++```bash+xcodebuild test -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS'+```++If you run into a test bundle load error related to code signing/Team ID, run without overriding code signing flags (the command above), or explicitly:++```bash+xcodebuild test -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS' CODE_SIGN_STYLE=Automatic+```++CI uses unsigned builds:++```bash+xcodebuild test -project Fluid.xcodeproj -scheme Fluid -destination 'platform=macOS' CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO+```+## LicenseThis project is licensed under the [Apache License 2.0](LICENSE).diff --git a/Sources/Fluid/Services/WhisperProvider.swift b/Sources/Fluid/Services/WhisperProvider.swiftindex 14cf66e9..b7f5b2e7 100644--- a/Sources/Fluid/Services/WhisperProvider.swift+++ b/Sources/Fluid/Services/WhisperProvider.swift@@ -16,6 +16,14 @@ final class WhisperProvider: TranscriptionProvider {private(set) var isReady: Bool = falseprivate var loadedModelName: String?+ private let overriddenModelDirectory: URL?+ private let urlSession: URLSession++ init(modelDirectory: URL? = nil, urlSession: URLSession = .shared) {+ self.overriddenModelDirectory = modelDirectory+ self.urlSession = urlSession+ }+/// Model filename to use - reads from the unified SpeechModel setting/// Models: tiny (~75MB), base (~142MB), small (~466MB), medium (~1.5GB), large (~2.9GB)private var modelName: String {@@ -23,10 +31,17 @@ final class WhisperProvider: TranscriptionProvider {}private var modelURL: URL {- guard let cacheDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {- preconditionFailure("Could not find caches directory")+ let directory: URL+ if let overriddenModelDirectory {+ directory = overriddenModelDirectory+ } else {+ guard let cacheDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {+ preconditionFailure("Could not find caches directory")+ }+ directory = cacheDir.appendingPathComponent("WhisperModels")}- return cacheDir.appendingPathComponent("WhisperModels").appendingPathComponent(self.modelName)++ return directory.appendingPathComponent(self.modelName)}private var modelDirectory: URL {@@ -113,53 +128,76 @@ final class WhisperProvider: TranscriptionProvider {DebugLogger.shared.info("WhisperProvider: Downloading from \(modelURLString)", source: "WhisperProvider")- do {- let (tempURL, response) = try await URLSession.shared.download(from: url)-- guard let httpResponse = response as? HTTPURLResponse else {- throw NSError(- domain: "WhisperProvider",- code: -1,- userInfo: [NSLocalizedDescriptionKey: "Invalid server response"]- )- }+ let maxAttempts = 3+ for attempt in 1...maxAttempts {+ do {+ let (tempURL, response) = try await self.urlSession.download(from: url)++ guard let httpResponse = response as? HTTPURLResponse else {+ throw NSError(+ domain: "WhisperProvider",+ code: -1,+ userInfo: [NSLocalizedDescriptionKey: "Invalid server response"]+ )+ }- guard httpResponse.statusCode == 200 else {- throw NSError(- domain: "WhisperProvider",- code: httpResponse.statusCode,- userInfo: [NSLocalizedDescriptionKey: "Failed to download model (HTTP \(httpResponse.statusCode))"]- )- }+ guard httpResponse.statusCode == 200 else {+ throw NSError(+ domain: "WhisperProvider",+ code: httpResponse.statusCode,+ userInfo: [NSLocalizedDescriptionKey: "Failed to download model (HTTP \(httpResponse.statusCode))"]+ )+ }- // Move to final location- if FileManager.default.fileExists(atPath: self.modelURL.path) {- try FileManager.default.removeItem(at: self.modelURL)- }- try FileManager.default.moveItem(at: tempURL, to: self.modelURL)-- DebugLogger.shared.info("WhisperProvider: Model downloaded successfully", source: "WhisperProvider")- } catch let error as NSError {- // Provide user-friendly error messages- if error.domain == NSURLErrorDomain {- let message: String- switch error.code {- case NSURLErrorNotConnectedToInternet:- message = "No internet connection. Please connect to the internet to download the Whisper model."- case NSURLErrorTimedOut:- message = "Download timed out. Please check your internet connection and try again."- case NSURLErrorCannotFindHost, NSURLErrorCannotConnectToHost:- message = "Cannot reach download server. Please check your internet connection."- default:- message = "Network error: \(error.localizedDescription)"+ // Move to final location+ if FileManager.default.fileExists(atPath: self.modelURL.path) {+ try FileManager.default.removeItem(at: self.modelURL)+ }+ try FileManager.default.moveItem(at: tempURL, to: self.modelURL)++ DebugLogger.shared.info("WhisperProvider: Model downloaded successfully", source: "WhisperProvider")+ return+ } catch let error as NSError {+ let isLastAttempt = attempt == maxAttempts++ // Provide user-friendly error messages+ if error.domain == NSURLErrorDomain {+ let message: String+ switch error.code {+ case NSURLErrorNotConnectedToInternet:+ message = "No internet connection. Please connect to the internet to download the Whisper model."+ case NSURLErrorTimedOut:+ message = "Download timed out. Please check your internet connection and try again."+ case NSURLErrorCannotFindHost, NSURLErrorCannotConnectToHost:+ message = "Cannot reach download server. Please check your internet connection."+ default:+ message = "Network error: \(error.localizedDescription)"+ }++ if isLastAttempt {+ throw NSError(+ domain: "WhisperProvider",+ code: error.code,+ userInfo: [NSLocalizedDescriptionKey: message]+ )+ }++ DebugLogger.shared.warning(+ "WhisperProvider: Download attempt \(attempt)/\(maxAttempts) failed (\(message)). Retrying...",+ source: "WhisperProvider"+ )+ } else {+ if isLastAttempt { throw error }+ DebugLogger.shared.warning(+ "WhisperProvider: Download attempt \(attempt)/\(maxAttempts) failed (\(error.localizedDescription)). Retrying...",+ source: "WhisperProvider"+ )}- throw NSError(- domain: "WhisperProvider",- code: error.code,- userInfo: [NSLocalizedDescriptionKey: message]- )++ // Backoff: 1s, 2s, 4s+ let delayNanos = UInt64(1_000_000_000) << UInt64(attempt - 1)+ try await Task.sleep(nanoseconds: delayNanos)}- throw error}}}diff --git a/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swiftnew file mode 100644index 00000000..68201136--- /dev/null+++ b/Tests/FluidDictationIntegrationTests/DictationE2ETests.swift@@ -0,0 +1,66 @@+import Foundation+import XCTest++@testable import FluidVoice_Debug++final class DictationE2ETests: XCTestCase {+ func testDictationEndToEnd_whisperTiny_transcribesFixture() async throws {+ // Arrange+ SettingsStore.shared.shareAnonymousAnalytics = false+ SettingsStore.shared.selectedSpeechModel = .whisperTiny++ let modelDirectory = Self.modelDirectoryForRun()+ try FileManager.default.createDirectory(at: modelDirectory, withIntermediateDirectories: true)++ let provider = WhisperProvider(modelDirectory: modelDirectory)++ // Act+ try await provider.prepare()+ let samples = try AudioFixtureLoader.load16kMonoFloatSamples(named: "dictation_fixture", ext: "wav")+ let result = try await provider.transcribe(samples)++ // Assert+ let raw = result.text.trimmingCharacters(in: .whitespacesAndNewlines)+ XCTAssertFalse(raw.isEmpty, "Expected non-empty transcription text.")++ let normalized = Self.normalize(raw)+ XCTAssertTrue(normalized.contains("hello"), "Expected transcription to contain 'hello'. Got: \(raw)")+ XCTAssertTrue(normalized.contains("fluid"), "Expected transcription to contain 'fluid'. Got: \(raw)")+ XCTAssertTrue(+ normalized.contains("voice") || normalized.contains("fluidvoice") || normalized.contains("boys"),+ "Expected transcription to contain 'voice' (or a close variant like 'boys'). Got: \(raw)"+ )+ }++ private static func modelDirectoryForRun() -> URL {+ // Use a stable path on CI so GitHub Actions cache can speed up runs.+ if ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" ||+ ProcessInfo.processInfo.environment["CI"] == "true"+ {+ guard let caches = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {+ preconditionFailure("Could not find caches directory")+ }+ return caches.appendingPathComponent("WhisperModels")+ }++ // Local runs: isolate per test execution.+ let base = FileManager.default.temporaryDirectory+ .appendingPathComponent("FluidVoiceTests", isDirectory: true)+ .appendingPathComponent(UUID().uuidString, isDirectory: true)+ return base.appendingPathComponent("WhisperModels", isDirectory: true)+ }++ private static func normalize(_ text: String) -> String {+ let lowered = text.lowercased()+ let noPunct = lowered.unicodeScalars.map { scalar -> Character in+ if CharacterSet.punctuationCharacters.contains(scalar) { return " " }+ return Character(scalar)+ }+ let collapsed = String(noPunct)+ .components(separatedBy: .whitespacesAndNewlines)+ .filter { !$0.isEmpty }+ .joined(separator: " ")++ return collapsed+ }+}diff --git a/Tests/FluidDictationIntegrationTests/Helpers/AudioFixtureLoader.swift b/Tests/FluidDictationIntegrationTests/Helpers/AudioFixtureLoader.swiftnew file mode 100644index 00000000..e8b9a9ec--- /dev/null+++ b/Tests/FluidDictationIntegrationTests/Helpers/AudioFixtureLoader.swift@@ -0,0 +1,100 @@+import AVFoundation+import Foundation++enum AudioFixtureLoader {+ enum LoaderError: LocalizedError {+ case fixtureNotFound(name: String, ext: String)+ case unsupportedAudio(String)++ var errorDescription: String? {+ switch self {+ case let .fixtureNotFound(name, ext):+ return "Audio fixture not found: \(name).\(ext)"+ case let .unsupportedAudio(message):+ return "Audio fixture could not be loaded/converted: \(message)"+ }+ }+ }++ /// Loads an audio fixture from the test bundle and converts it to 16kHz mono Float32 samples.+ static func load16kMonoFloatSamples(named name: String, ext: String) throws -> [Float] {+ let bundle = Bundle(for: BundleToken.self)+ guard let url = bundle.url(forResource: name, withExtension: ext) else {+ throw LoaderError.fixtureNotFound(name: name, ext: ext)+ }++ let inputFile = try AVAudioFile(forReading: url)+ let inputFormat = inputFile.processingFormat++ let desiredFormat = AVAudioFormat(+ commonFormat: .pcmFormatFloat32,+ sampleRate: 16_000,+ channels: 1,+ interleaved: false+ )!++ // Fast-path: already 16k mono float+ if inputFormat.sampleRate == desiredFormat.sampleRate,+ inputFormat.channelCount == desiredFormat.channelCount,+ inputFormat.commonFormat == desiredFormat.commonFormat+ {+ let buffer = try readAllFrames(file: inputFile, format: inputFormat)+ return try extractMonoFloatSamples(buffer: buffer)+ }++ guard let converter = AVAudioConverter(from: inputFormat, to: desiredFormat) else {+ throw LoaderError.unsupportedAudio("Could not create AVAudioConverter.")+ }++ let inputFrameCount = AVAudioFrameCount(inputFile.length)+ let ratio = desiredFormat.sampleRate / inputFormat.sampleRate+ let estimatedOutputFrames = max(1, AVAudioFrameCount(Double(inputFrameCount) * ratio) + 1)++ let inputBuffer = try readAllFrames(file: inputFile, format: inputFormat)+ guard let outputBuffer = AVAudioPCMBuffer(pcmFormat: desiredFormat, frameCapacity: estimatedOutputFrames) else {+ throw LoaderError.unsupportedAudio("Could not allocate output buffer.")+ }++ var didProvideInput = false+ var conversionError: NSError?+ converter.convert(to: outputBuffer, error: &conversionError) { _, outStatus in+ if didProvideInput {+ outStatus.pointee = .endOfStream+ return nil+ }+ didProvideInput = true+ outStatus.pointee = .haveData+ return inputBuffer+ }++ if let conversionError {+ throw LoaderError.unsupportedAudio(conversionError.localizedDescription)+ }++ return try extractMonoFloatSamples(buffer: outputBuffer)+ }++ private static func readAllFrames(file: AVAudioFile, format: AVAudioFormat) throws -> AVAudioPCMBuffer {+ let frameCount = AVAudioFrameCount(file.length)+ guard let buffer = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: max(frameCount, 1)) else {+ throw LoaderError.unsupportedAudio("Could not allocate input buffer.")+ }+ try file.read(into: buffer)+ return buffer+ }++ private static func extractMonoFloatSamples(buffer: AVAudioPCMBuffer) throws -> [Float] {+ guard buffer.format.channelCount == 1 else {+ throw LoaderError.unsupportedAudio("Expected mono audio after conversion, got \(buffer.format.channelCount) channels.")+ }+ guard let channelData = buffer.floatChannelData else {+ throw LoaderError.unsupportedAudio("Expected Float32 PCM data (floatChannelData was nil).")+ }++ let frames = Int(buffer.frameLength)+ return Array(UnsafeBufferPointer(start: channelData[0], count: frames))+ }++ /// Used to locate this test bundle reliably.+ private final class BundleToken {}+}diff --git a/Tests/FluidDictationIntegrationTests/Resources/README.md b/Tests/FluidDictationIntegrationTests/Resources/README.mdnew file mode 100644index 00000000..99d82de0--- /dev/null+++ b/Tests/FluidDictationIntegrationTests/Resources/README.md@@ -0,0 +1,11 @@+# Dictation audio fixture++`dictation_fixture.wav` is a short, deterministic fixture used by the CI end-to-end dictation integration test.++If you need to regenerate/replace it, keep it:+- WAV, mono, 16kHz, 16-bit PCM+- ~2–4 seconds+- phrase similar to: “hello fluid voice”++Note: ensure you have appropriate rights to redistribute any replacement audio.+