Add push-to-talk voice notes functionality

- Added voice note support to BitchatMessage with audio data and duration
- Updated binary protocol to encode/decode voice notes (flag 0x40)
- Created AudioRecordingService for recording up to 10s voice clips
- Created AudioPlaybackService for playing voice notes
- Added microphone permission to Info.plist and project.yml
- Implemented push-to-talk UI with mic button in ContentView
- Voice notes use AAC compression at 16kHz/32kbps for small file sizes
- Added play/pause buttons for voice notes in message list
- Voice notes display as '🎤 Voice note (X.Xs)' in chat
- Platform-specific audio session handling for iOS/macOS
This commit is contained in:
jack
2025-07-03 01:13:16 +02:00
parent d142fde11d
commit 94a9888ef5
9 changed files with 470 additions and 8 deletions
+28
View File
@@ -27,6 +27,8 @@ class ChatViewModel: ObservableObject {
@Published var privateMessageNotification: (sender: String, message: String)? = nil
let meshService = BluetoothMeshService()
let audioRecorder = AudioRecordingService()
let audioPlayer = AudioPlaybackService()
private let userDefaults = UserDefaults.standard
private let nicknameKey = "bitchat.nickname"
private var nicknameSaveTimer: Timer?
@@ -471,4 +473,30 @@ extension ChatViewModel: BitchatDelegate {
return Array(Set(mentions)) // Remove duplicates
}
func sendVoiceNote(_ audioData: Data, duration: TimeInterval) {
let message = BitchatMessage(
sender: nickname,
content: "🎤 Voice note (\(String(format: "%.1f", duration))s)",
timestamp: Date(),
isRelay: false,
originalSender: nil,
voiceNoteData: audioData,
voiceNoteDuration: duration
)
messages.append(message)
// Send via mesh
meshService.sendVoiceNote(audioData, duration: duration)
}
func playVoiceNote(message: BitchatMessage) {
guard let audioData = message.voiceNoteData else { return }
audioPlayer.togglePlayback(messageID: message.id, audioData: audioData) { result in
if case .failure(let error) = result {
print("[AUDIO] Failed to play voice note: \(error)")
}
}
}
}