1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] using flutterTTS synthesizeToFile and store the file in appStorage in flutter

Discussão em 'Mobile' iniciado por Stack, Outubro 1, 2024 às 09:53.

  1. Stack

    Stack Membro Participativo

    i am converting the text to .mp3 file using FlutterTTS and store in getApplicationDocumentDirectory but while using synthesizeToFile method then it will automatically add the external storage URL before the appStorage URL.

    Future synthesizeTextToMP3(String text) async { FlutterTts flutterTts = FlutterTts();

    AudioPlayer audioPlayer = AudioPlayer();

    // Get the application documents directory

    // Set parameters for TTS
    await flutterTts.setLanguage("en-US");
    await flutterTts.setSpeechRate(0.5);
    await flutterTts.setVolume(1.0);
    await flutterTts.setPitch(1.0);

    // Synthesize to file
    await flutterTts.synthesizeToFile(
    text, "The File is in App Storage: $filePath");

    // Check if the file exists before playing
    final file = File(filePath);
    if (await file.exists()) {
    audioPlayer.play(DeviceFileSource(filePath));
    // print('MP3 file saved at: $filePath');
    } else {
    // print('File does not exist at: $filePath');
    }


    }

    output: Successfully created file : /external/audio/media/1000113932/The File is in App Storage: /data/user/0/com.desmond.seabee/app_flutter/seabeestudypath.mp3

    added URL is: /external/audio/media/1000113932/ the URL i only want : /data/user/0/com.desmond.seabee/app_flutter/seabeestudypath.mp3

    Continue reading...

Compartilhe esta Página