englishSpeaking.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. // 练习方式
  2. export type PracticeMode = 'rounds' | 'time' | 'free'
  3. // 评分方式
  4. export type ScoreMode = 'numeric' | 'letter' | 'comment_only'
  5. // AI 角色
  6. export interface Role {
  7. id: string
  8. name: string
  9. avatar: string
  10. avatarUrl?: string
  11. identity: string
  12. personality: string
  13. difficulty: number
  14. isRecommended?: boolean
  15. }
  16. // 评估维度
  17. export interface EvalDimensions {
  18. accuracy: boolean
  19. fluency: boolean
  20. completeness: boolean
  21. rhythm: boolean
  22. }
  23. // 练习设置
  24. export interface PracticeSettings {
  25. mode: PracticeMode
  26. rounds: number
  27. duration: number // 时长(分钟)
  28. showEnglish: boolean
  29. taskHint: boolean
  30. stutterHint: boolean
  31. }
  32. // 评估设置
  33. export interface EvaluationSettings {
  34. showReport: boolean
  35. dimensions: EvalDimensions
  36. scoreMode: ScoreMode
  37. }
  38. // 学习目标
  39. export interface LearningGoals {
  40. vocabulary: string[]
  41. sentences: string[]
  42. }
  43. // 话题讨论配置
  44. export interface TopicDiscussionConfig {
  45. topic: string
  46. grade: string
  47. selectedRole: string
  48. learningGoals: LearningGoals
  49. practice: PracticeSettings
  50. evaluation: EvaluationSettings
  51. }
  52. // 推荐任务卡片
  53. export interface TopicDiscussionTask {
  54. id: string
  55. titleZh: string
  56. titleEn: string
  57. subtitle: string
  58. difficulty: 1 | 2 | 3
  59. rounds: number
  60. durationMinutes: number
  61. vocabulary: string[]
  62. sentences: string[]
  63. note: string
  64. }
  65. // 教材单元
  66. export interface CurriculumUnit {
  67. id: string
  68. number: string
  69. title: string
  70. description: string
  71. vocabulary: string[]
  72. sentences: string[]
  73. }
  74. // 教材年级
  75. export interface CurriculumGrade {
  76. id: string
  77. name: string
  78. semester: string
  79. units: CurriculumUnit[]
  80. }
  81. // 教材
  82. export interface CurriculumTextbook {
  83. id: string
  84. name: string
  85. grades: CurriculumGrade[]
  86. }
  87. // 教材数据根
  88. export interface CurriculumData {
  89. textbooks: CurriculumTextbook[]
  90. }
  91. // 创建方式
  92. export type CreationMode = 'smart' | 'ai' | 'manual'
  93. // 页面层级
  94. export type PageMode = 'layer1' | 'layer2' | 'config'
  95. // 练习类型
  96. export type ExerciseType = 'speaking' | 'listening' | 'reading' | 'writing'
  97. // ==================== 预览组件类型定义 ====================
  98. // 评分等级
  99. export type ScoreLevel = 'excellent' | 'good' | 'fair' | 'needsWork'
  100. // 评分展示方式(复用配置侧的 ScoreMode)
  101. export type ScoreDisplayMode = ScoreMode
  102. // 对话统计数据
  103. export interface DialogueStatistics {
  104. totalRounds: number
  105. averageScore: number
  106. highestScore: number
  107. highestRound: number
  108. grammarErrors: number
  109. excellentExpressions: number
  110. totalDuration: number // 秒
  111. }
  112. // 下次挑战推荐
  113. export interface NextChallenge {
  114. difficulty?: string
  115. unlockedTopic?: string
  116. suggestedMode?: string
  117. }
  118. // 单句评价
  119. export interface SentenceEvaluation {
  120. id: string
  121. round: number
  122. role: 'ai' | 'student'
  123. content: string
  124. contentZh?: string
  125. audioUrl?: string
  126. audioDuration?: number
  127. score?: number
  128. pronunciation?: {
  129. accuracy: number
  130. intonation: number
  131. stress: number
  132. fluency: number
  133. }
  134. feedback?: {
  135. highlights: string[]
  136. corrections: {
  137. original: string
  138. corrected: string
  139. explanation: string
  140. }[]
  141. suggestions: string[]
  142. }
  143. }
  144. // 整体评价报告
  145. export interface OverallEvaluation {
  146. overallScore: number
  147. scoreLevel: ScoreLevel
  148. percentile: number
  149. dimensions: {
  150. fluency: number
  151. interaction: number
  152. vocabulary: number
  153. grammar: number
  154. }
  155. aiComment: string
  156. highlights: string[]
  157. improvements: string[]
  158. nextChallenge: NextChallenge
  159. statistics: DialogueStatistics
  160. sentenceEvaluations: SentenceEvaluation[]
  161. }
  162. // 预览用 AI 角色(扩展配置侧的 Role)
  163. export interface PreviewAIRole {
  164. id: string
  165. name: string
  166. avatar: string
  167. identity: string
  168. personality: string
  169. speakingStyle: 'formal' | 'casual' | 'playful'
  170. speed: 'slow' | 'normal' | 'fast'
  171. isCustom: boolean
  172. isRecommended?: boolean
  173. }
  174. // 消息状态
  175. export type MessageStatus = 'loading' | 'done' | 'error'
  176. // 对话消息
  177. export interface PreviewChatMessage {
  178. id: string
  179. role: 'ai' | 'student'
  180. content: string
  181. timestamp: Date
  182. status?: MessageStatus
  183. error?: string
  184. /** true 表示这个错误无法重试(如 session 404/409),UI 应提示用户重开 */
  185. unrecoverable?: boolean
  186. audioBlob?: Blob
  187. evaluation?: {
  188. dimensions: {
  189. accuracy: 'excellent' | 'good' | 'improve'
  190. fluency: 'excellent' | 'good' | 'improve'
  191. completeness: 'excellent' | 'good' | 'improve'
  192. rhythm: 'excellent' | 'good' | 'improve'
  193. }
  194. suggestion: string
  195. betterExpression?: string
  196. suggestedWords?: string[]
  197. wordAnalysis?: {
  198. word: string
  199. status: 'correct' | 'improvable'
  200. userPronunciation?: string
  201. standardPronunciation?: string
  202. tip?: string
  203. }[]
  204. }
  205. }
  206. // ==================== 对话引擎类型定义 ====================
  207. // SSE 事件类型
  208. export type SSEEvent =
  209. | { type: 'transcript'; text: string }
  210. | { type: 'token'; text: string }
  211. | { type: 'done'; isComplete: boolean }
  212. // 对话会话配置
  213. export interface SessionConfig {
  214. topic: string
  215. grade: string
  216. roleId: string
  217. totalRounds: number
  218. vocabulary?: string[]
  219. sentences?: string[]
  220. }
  221. // 对话会话信息 (createSession 返回)
  222. export interface SessionInfo {
  223. sessionId: string
  224. totalRounds: number
  225. currentRound: number
  226. expiresAt: string | null
  227. }
  228. // 开场白生成结果 (generateGreeting 返回)
  229. export interface GreetingInfo {
  230. aiMessage: string
  231. }
  232. // 用于启动 chat view 的最小 session 信息(父组件 createSession 后传给 DialogueChatView)
  233. export interface SessionStartInfo {
  234. sessionId: string
  235. expiresAt: string | null
  236. }
  237. // 对话报告
  238. export interface DialogueReport {
  239. evaluation: OverallEvaluation
  240. }
  241. export interface TaskHint {
  242. practice_level: string
  243. conversation_topic: string
  244. current_question: string
  245. example_sentences: {
  246. english: string
  247. chinese: string
  248. }[]
  249. key_vocabulary: {
  250. word: string
  251. meaning: string
  252. }[]
  253. }
  254. // 对话 API 接口
  255. export interface DialogueAPI {
  256. createSession(config: SessionConfig): Promise<SessionInfo>
  257. /** Throws DOMException('AbortError') on signal abort; throws DialogueApiError on non-OK HTTP. */
  258. generateGreeting(sessionId: string, signal?: AbortSignal): Promise<GreetingInfo>
  259. generateTaskHint(sessionId: string): Promise<TaskHint>
  260. speak(sessionId: string, audioBlob: Blob, signal: AbortSignal): AsyncGenerator<SSEEvent>
  261. getReport(sessionId: string): Promise<DialogueReport>
  262. }
  263. // 徽章成就
  264. export interface BadgeAchievement {
  265. id: string
  266. name: string
  267. nameEn: string
  268. icon: string
  269. description: string
  270. }
  271. // 预览对话状态
  272. export type PreviewDialogueState = 'ready' | 'chatting' | 'completed'