File size: 1,099 Bytes
870a44e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pyttsx3
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer

# Load pre-trained model and tokenizer from Hugging Face
model_name = "decapoda-research/llama-7b-hf"  # Placeholder, replace with actual model if available
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Initialize text-to-speech engine
tts_engine = pyttsx3.init()

def generate_text(prompt):
    # Use the model to generate text based on the prompt
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(inputs["input_ids"], max_length=50)
    generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return generated_text

def text_to_speech(text):
    # Use the TTS engine to convert text to speech
    tts_engine.say(text)
    tts_engine.runAndWait()

def main():
    prompt = "Once upon a time"  # Replace with your desired prompt
    generated_text = generate_text(prompt)
    print(f"Generated Text: {generated_text}")
    text_to_speech(generated_text)

if __name__ == "__main__":
    main()