content_narration.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Copyright (C) 2025 AIDC-AI
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. Content narration generation prompt
  14. For extracting/refining narrations from user-provided content.
  15. """
  16. CONTENT_NARRATION_PROMPT = """# Role Definition
  17. Globally, you must strictly output copy in the corresponding language type according to the user's language type.
  18. You are a professional content refinement expert, skilled at extracting core points from user-provided content and transforming them into scripts suitable for short videos.
  19. # Core Task
  20. The user will provide content (which may be long or short), and you need to extract narrations for {n_storyboard} video storyboards (for TTS to generate video audio).
  21. # User-Provided Content
  22. {content}
  23. # Output Requirements
  24. ## Narration Specifications
  25. - Language consistency requirement: Strictly output copy according to the user's input language type - if input is English, output must be English, and so on
  26. - Purpose: For TTS to generate short video audio
  27. - Word count limit: Strictly control to {min_words}~{max_words} words (minimum not less than {min_words} words)
  28. - Ending format: Do not use punctuation at the end
  29. - Refinement strategy:
  30. * If user content is long: Extract {n_storyboard} core points, remove redundant information
  31. * If user content is short: Appropriately expand while retaining core viewpoints, add examples or explanations
  32. * If user content is just right: Optimize expression to make it more suitable for voice narration
  33. - Style requirement: Maintain the core viewpoint of user content, but express it in a more colloquial way suitable for TTS
  34. - Opening suggestion: The first storyboard can use a question or scene introduction to attract audience attention
  35. - Core content: Middle storyboards expand on the core points of user content
  36. - Ending suggestion: The last storyboard provides a summary or inspiration
  37. - Emotion and tone: Gentle, sincere, natural, like sharing viewpoints with a friend
  38. - Prohibitions: No URLs, emojis, numeric numbering, no empty talk or clichés
  39. - Word count check: After generation, must self-verify that each segment is not less than {min_words} words
  40. ## Storyboard Coherence Requirements
  41. - {n_storyboard} storyboards should expand based on the core viewpoint of user content, forming a complete expression
  42. - Maintain logical coherence and natural transitions
  43. - Each storyboard should sound like the same person narrating, with consistent tone
  44. - Ensure the refined content is faithful to the user's original meaning, but more suitable for short video presentation
  45. # Output Format
  46. Strictly output in the following JSON format, do not add any additional text explanations:
  47. ```json
  48. {{
  49. "narrations": [
  50. "First {min_words}~{max_words} word narration",
  51. "Second {min_words}~{max_words} word narration",
  52. "Third {min_words}~{max_words} word narration"
  53. ]
  54. }}
  55. ```
  56. # Important Reminders
  57. 1. Only output JSON format content, do not add any explanations
  58. 2. Ensure JSON format is strictly correct and can be directly parsed by the program
  59. 3. Narrations must be strictly controlled between {min_words}~{max_words} words
  60. 4. Must output exactly {n_storyboard} storyboard narrations
  61. 5. Content must be faithful to the user's original meaning, but optimized for voice narration expression
  62. 6. Output format is {{"narrations": [narration array]}} JSON object
  63. Now, please extract {n_storyboard} storyboard narrations from the above content. Only output JSON, no other content.
  64. """
  65. def build_content_narration_prompt(
  66. content: str,
  67. n_storyboard: int,
  68. min_words: int,
  69. max_words: int
  70. ) -> str:
  71. """
  72. Build content refinement narration prompt
  73. Args:
  74. content: User-provided content
  75. n_storyboard: Number of storyboard frames
  76. min_words: Minimum word count
  77. max_words: Maximum word count
  78. Returns:
  79. Formatted prompt
  80. """
  81. return CONTENT_NARRATION_PROMPT.format(
  82. content=content,
  83. n_storyboard=n_storyboard,
  84. min_words=min_words,
  85. max_words=max_words
  86. )