I want to make datasets for medicine! Give me datasets code with comma. I need datasets in txt with comma. And don't need python. Only need datasets. pip install gtts pydub

from gtts import gTTS

from pydub import AudioSegment

from pydub.playback import play

import os

import random


# Function to generate text-to-speech

def text_to_speech(text, output_file="output.mp3", lang="en", slow=False):

    # Generate TTS using gTTS

    tts = gTTS(text=text, lang=lang, slow=slow)

    tts.save(output_file)

    print(f"Text-to-speech saved to {output_file}")


# Function to add light breathing sounds

def add_breathing_sounds(audio_file, breathing_file="breathing.wav", output_file="output_with_breathing.mp3"):

    # Load the TTS audio

    audio = AudioSegment.from_mp3(audio_file)


    # Load the breathing sound

    breathing = AudioSegment.from_wav(breathing_file)

    breathing = breathing - 10 # Reduce volume of breathing sound by 10 dB


    # Randomly insert breathing sounds into the audio

    final_audio = AudioSegment.empty()

    chunk_length = 2000 # Split audio into 2-second chunks

    overlap = 100 # Overlap between chunks for smooth transitions


    for i in range(0, len(audio), chunk_length):

        chunk = audio[i:i + chunk_length]

        final_audio += chunk


        # Randomly add breathing sound (30% chance)

        if random.random() < 0.3 and len(final_audio) > 1000: # Ensure breathing isn't added at the very start

            final_audio = final_audio.append(breathing, crossfade=overlap)


    # Export the final audio

    final_audio.export(output_file, format="mp3")

    print(f"Audio with breathing saved to {output_file}")


# Main function

def main():

    # Input text

    text = input("Enter the text you want to convert to speech: ")


    # Generate TTS

    tts_output = "tts_output.mp3"

    text_to_speech(text, output_file=tts_output, lang="en", slow=False)


    # Add breathing sounds

    final_output = "final_output.mp3"

    add_breathing_sounds(tts_output, output_file=final_output)


    # Play the final audio

    play(AudioSegment.from_mp3(final_output))


    # Clean up temporary files

    os.remove(tts_output)


if __name__ == "__main__":

    main()

Comments