suno-ai / bark

🔊 Text-Prompted Generative Audio Model
MIT License
33.72k stars 4k forks source link

Generated audio is not at all what I wrote in the prompt, unreliable results #564

Open IveMalfunctioned opened 2 months ago

IveMalfunctioned commented 2 months ago

This code:

`from bark import SAMPLE_RATE, generate_audio, preload_models from scipy.io.wavfile import write as write_wav from IPython.display import Audio import datetime

download and load all models

preload_models()

generate audio from text

current_time = datetime.datetime.now().strftime("%I:%M %p") text_prompt = "The current time is " + current_time audio_array = generate_audio(text_prompt)

save audio to disk

write_wav("bark_generation.wav", SAMPLE_RATE, audio_array)

play text in notebook

Audio(audio_array, rate=SAMPLE_RATE)`

somehow resulted in this... bark_generation.webm

python 3.12.2 torch 2.3 bark installed with git clone command

JonathanFly commented 1 month ago

What's the actual string being generated there? Bark has trouble with very short sentences, and sometimes number formatting like that. Try something like this instead:

def current_date_time_in_words():
    now = datetime.now()
    day_of_week = now.strftime("%A")
    month = now.strftime("%B")
    day = ordinal(now.day)
    year = now.year
    hour = now.hour
    minute = now.minute

    time_of_day_str = time_of_day(hour)

    if minute == 0:
        minute_str = ""
    elif minute == 1:
        minute_str = "1 minute past"
    elif minute == 15:
        minute_str = "quarter past"
    elif minute == 30:
        minute_str = "half past"
    elif minute == 45:
        minute_str = "quarter to "
        hour += 1
    elif minute < 30:
        minute_str = str(minute) + " minutes past"
    else:
        minute_str = str(60 - minute) + " minutes to "
        hour += 1

    hour_str = str(hour if hour <= 12 else hour - 12)

    if minute_str:
        time_str = minute_str + " " + hour_str
    else:
        time_str = hour_str + " o'clock"

    time_string = f"{day_of_week}, {month} {day}, {year}, {time_str} {time_of_day_str}."

    return time_string