feat: save repeat audio on mic record and rename button to play repeat
This commit is contained in:
@@ -7,7 +7,6 @@ import 'package:http/http.dart' as http;
|
||||
|
||||
import 'models.dart';
|
||||
import 'generated_content.dart';
|
||||
import 'a0_core.dart';
|
||||
|
||||
class AiConnectionResult {
|
||||
const AiConnectionResult({required this.ok, required this.message});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
@@ -16,6 +18,7 @@ class VoiceService {
|
||||
final SpeechToText _stt = SpeechToText();
|
||||
final AudioRecorder _recorder = AudioRecorder();
|
||||
final AudioPlayer _player = AudioPlayer();
|
||||
StreamSubscription<void>? _playerSub;
|
||||
bool _speechReady = false;
|
||||
bool _ttsInitialized = false;
|
||||
|
||||
@@ -92,12 +95,23 @@ class VoiceService {
|
||||
|
||||
Future<String?> stopRecording() => _recorder.stop();
|
||||
|
||||
Future<void> playRecording(String path) async {
|
||||
await _player.stop();
|
||||
Future<void> playRecording(String path, {VoidCallback? onComplete}) async {
|
||||
await stopRecordingPlayback();
|
||||
if (onComplete != null) {
|
||||
_playerSub = _player.onPlayerComplete.listen((_) {
|
||||
_playerSub?.cancel();
|
||||
_playerSub = null;
|
||||
onComplete();
|
||||
});
|
||||
}
|
||||
await _player.play(DeviceFileSource(path));
|
||||
}
|
||||
|
||||
Future<void> stopRecordingPlayback() => _player.stop();
|
||||
Future<void> stopRecordingPlayback() async {
|
||||
await _playerSub?.cancel();
|
||||
_playerSub = null;
|
||||
await _player.stop();
|
||||
}
|
||||
|
||||
Future<void> deleteRecording(String? path) async {
|
||||
if (path == null || path.isEmpty) return;
|
||||
|
||||
Reference in New Issue
Block a user