Advertisement
Awagner14

Python Function and Chat gpt prompt to convert text to ssml

Mar 7th, 2024
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. # # # Turn Text into SSML for Voice Synthesis###
  2. def textToSSMLConverter(voice_description , text_input):
  3. print ("\n\033[37mConverting text to Speech Synthesis Markup Language"
  4. )
  5. response = openai.chat.completions.create(
  6. model=config["ChatGPTmodel"],
  7. messages=[
  8. {
  9. "role": "system",
  10. "content": "Refine Text with SSML for natural spoken dialogue. Use moderate natural speech pauses. Replace all commas with periods. Assess the inputted text and Voice description " + voice_description + " and increase pauses and phoneme tags for more emotional or impactful words. Break Tags: '<break time=\"*use specific, varied values < 200ms*\"/> for precise pause lengths. Switch ' and , and . for Break Tags. Write out all numbers and abbreviations. Phoneme Tag <phoneme alphabet=\"x-sampa\" ph='m@\"hA:g@%ni:'> for specific word pronunciation. <speak> Text </speak> Use phoneme tags for: names, places, key words and multisyllable words. Use phoneme tags and break tags to create emphasis and emotion for words or phrases. Make heavy use of the emphasis element for important words and impactful phrases: The emphasis element format: <emphasis level = \"level\" >text</emphasis>, levels = moderate, reduced. The prosody element format <prosody \"parameter 1\" = \"level\" \"parameter 2\" = \"level\" \"parameter 3\" = \"level\" >Text</prosody>. Use pitch, rate, and volume generously to further refine the text to have natural spoken variations in voice based on emotional expression of the sentence. The prosody element format <prosody \"parameter 1\" = \"level\" \"parameter 2\" = \"level\" \"parameter 3\" = \"level\" >Text</prosody>. Prosody Attributes and levels: pitch: low, medium, high. rates: slow, medium. Do not change volume. Vary prosody frequently. Only use pitch, rate and emphasis. Remove parenthetical descriptions. Respond with the updated ssml script only, not in a code block. \n\n" + text_input
  11. },
  12. {"role": "user", "content": text_input}
  13. ],
  14. temperature=0.45,
  15. max_tokens=4095,
  16. top_p=0.7,
  17. frequency_penalty=0,
  18. presence_penalty=0
  19. )
  20. #print(response.choices[0].message.content)
  21. print ("\033[37mText \033[32msuccessfully \033[37mconverted to SSML")
  22. return response.choices[0].message.content
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement