# VoiceFlo Audio Access Troubleshooting Guide

## Error -10877: Audio Unit Not Found

This error typically indicates that Core Audio cannot access the microphone input due to missing entitlements or sandbox restrictions.

### Quick Fix Checklist

#### 1. ✅ Entitlements File
Ensure your `VoiceFlo.entitlements` file contains:
```xml
<key>com.apple.security.device.audio-input</key>
<true/>
```

#### 2. ✅ Info.plist Configuration
Your `Info.plist` must include:
```xml
<key>NSMicrophoneUsageDescription</key>
<string>VoiceFlo needs microphone access to transcribe your voice into text.</string>

<key>NSSpeechRecognitionUsageDescription</key>
<string>VoiceFlo uses speech recognition to convert your spoken words into text.</string>
```

#### 3. ✅ Xcode Project Settings
In Xcode:
1. Go to your app target → **Signing & Capabilities**
2. Ensure **Hardened Runtime** is enabled
3. Under Hardened Runtime, check **Audio Input** capability
4. Under **App Sandbox** (if using), ensure **Audio Input** is checked

#### 4. ✅ Reset Permissions
Run in Terminal:
```bash
# Reset microphone permissions for your app
tccutil reset Microphone com.yourcompany.VoiceFlo

# Or reset all microphone permissions
tccutil reset Microphone
```

#### 5. ✅ Verify System Settings
1. Open **System Settings > Privacy & Security > Microphone**
2. Ensure VoiceFlo is in the list and **enabled**
3. If not in the list, restart the app to trigger permission dialog

### Testing Commands

```bash
# Test if other apps can access microphone
# This should show audio levels if working
system_profiler SPAudioDataType

# Kill and restart audio daemon (requires admin)
sudo killall coreaudiod

# Check if another app is using microphone
lsof | grep -i audio
```

### Common Issues

#### Issue: App shows in System Settings but still can't access mic
**Solution**: Delete app from microphone list, restart app, grant permission again

#### Issue: Permission granted but getting -10877 error
**Solution**: Missing entitlements file or incorrect bundle ID in entitlements

#### Issue: Works in Debug but fails in Release
**Solution**: Check Release build has same entitlements and signing configuration

#### Issue: "Another app is using microphone"
**Solution**: 
```bash
# Find apps using audio
ps aux | grep -i audio
# Kill specific processes if needed
```

### Debugging Steps

1. **Run Full Diagnostic**:
   ```swift
   await streamingManager.fullDiagnostic()
   ```

2. **Check Console Output** for detailed error information

3. **Test Microphone Separately**:
   - Open System Settings → Sound → Input
   - Speak and verify input levels are detected
   - Try recording in QuickTime Player

4. **Verify Entitlements**:
   ```bash
   # Check your built app's entitlements
   codesign -d --entitlements :- /path/to/VoiceFlo.app
   ```

### Development vs Production

#### Development (Debug):
- Temporary entitlements may work
- Less strict sandbox enforcement

#### Production (Release/App Store):
- Must have proper entitlements
- Full sandbox enforcement
- Must pass App Review audio usage guidelines

### If All Else Fails

1. **Clean Build Folder** (⌘+Shift+K)
2. **Delete Derived Data**
3. **Restart Xcode**
4. **Reboot Mac** (clears audio daemon cache)
5. **Test on different Mac** to isolate environment issues

### Contact Support

If issue persists, provide:
- Full console output from `fullDiagnostic()`
- Xcode project settings screenshots
- System Settings → Microphone screenshot
- macOS version and Mac model