transcription.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Derived from vercel/ai-elements (skills/ai-elements/scripts/transcription.tsx).
  3. * Copyright 2023 Vercel, Inc. Licensed under Apache-2.0.
  4. * Modified by ZCode: local integration, formatting and adaptations.
  5. * See THIRD-PARTY-NOTICES.md in the repository root for license and provenance.
  6. */
  7. "use client";
  8. import { Transcription, TranscriptionSegment } from "@/components/ai-elements/transcription";
  9. import type { Experimental_TranscriptionResult as TranscriptionResult } from "ai";
  10. import { useCallback, useRef, useState } from "react";
  11. const segments: TranscriptionResult["segments"] = [
  12. {
  13. endSecond: 0.219,
  14. startSecond: 0.119,
  15. text: "You",
  16. },
  17. {
  18. endSecond: 0.259,
  19. startSecond: 0.219,
  20. text: " ",
  21. },
  22. {
  23. endSecond: 0.439,
  24. startSecond: 0.259,
  25. text: "can",
  26. },
  27. {
  28. endSecond: 0.459,
  29. startSecond: 0.439,
  30. text: " ",
  31. },
  32. {
  33. endSecond: 0.699,
  34. startSecond: 0.459,
  35. text: "build",
  36. },
  37. {
  38. endSecond: 0.72,
  39. startSecond: 0.699,
  40. text: " ",
  41. },
  42. {
  43. endSecond: 0.799,
  44. startSecond: 0.72,
  45. text: "and",
  46. },
  47. {
  48. endSecond: 0.879,
  49. startSecond: 0.799,
  50. text: " ",
  51. },
  52. {
  53. endSecond: 1.339,
  54. startSecond: 0.879,
  55. text: "host",
  56. },
  57. {
  58. endSecond: 1.359,
  59. startSecond: 1.339,
  60. text: " ",
  61. },
  62. {
  63. endSecond: 1.539,
  64. startSecond: 1.36,
  65. text: "many",
  66. },
  67. {
  68. endSecond: 1.6,
  69. startSecond: 1.539,
  70. text: " ",
  71. },
  72. {
  73. endSecond: 1.86,
  74. startSecond: 1.6,
  75. text: "different",
  76. },
  77. {
  78. endSecond: 1.899,
  79. startSecond: 1.86,
  80. text: " ",
  81. },
  82. {
  83. endSecond: 2.099,
  84. startSecond: 1.899,
  85. text: "types",
  86. },
  87. {
  88. endSecond: 2.119,
  89. startSecond: 2.099,
  90. text: " ",
  91. },
  92. {
  93. endSecond: 2.2,
  94. startSecond: 2.119,
  95. text: "of",
  96. },
  97. {
  98. endSecond: 2.259,
  99. startSecond: 2.2,
  100. text: " ",
  101. },
  102. {
  103. endSecond: 2.96,
  104. startSecond: 2.259,
  105. text: "applications",
  106. },
  107. {
  108. endSecond: 3.479,
  109. startSecond: 2.96,
  110. text: " ",
  111. },
  112. {
  113. endSecond: 3.699,
  114. startSecond: 3.48,
  115. text: "from",
  116. },
  117. {
  118. endSecond: 3.779,
  119. startSecond: 3.699,
  120. text: " ",
  121. },
  122. {
  123. endSecond: 4.099,
  124. startSecond: 3.779,
  125. text: "static",
  126. },
  127. {
  128. endSecond: 4.179,
  129. startSecond: 4.099,
  130. text: " ",
  131. },
  132. {
  133. endSecond: 4.519,
  134. startSecond: 4.179,
  135. text: "sites",
  136. },
  137. {
  138. endSecond: 4.539,
  139. startSecond: 4.519,
  140. text: " ",
  141. },
  142. {
  143. endSecond: 4.759,
  144. startSecond: 4.539,
  145. text: "with",
  146. },
  147. {
  148. endSecond: 4.799,
  149. startSecond: 4.759,
  150. text: " ",
  151. },
  152. {
  153. endSecond: 4.939,
  154. startSecond: 4.799,
  155. text: "your",
  156. },
  157. {
  158. endSecond: 4.96,
  159. startSecond: 4.939,
  160. text: " ",
  161. },
  162. {
  163. endSecond: 5.219,
  164. startSecond: 4.96,
  165. text: "favorite",
  166. },
  167. {
  168. endSecond: 5.319,
  169. startSecond: 5.219,
  170. text: " ",
  171. },
  172. {
  173. endSecond: 5.939,
  174. startSecond: 5.319,
  175. text: "framework,",
  176. },
  177. {
  178. endSecond: 5.96,
  179. startSecond: 5.939,
  180. text: " ",
  181. },
  182. {
  183. endSecond: 6.519,
  184. startSecond: 5.96,
  185. text: "multi-tenant",
  186. },
  187. {
  188. endSecond: 6.559,
  189. startSecond: 6.519,
  190. text: " ",
  191. },
  192. {
  193. endSecond: 7.259,
  194. startSecond: 6.559,
  195. text: "applications",
  196. },
  197. {
  198. endSecond: 7.699,
  199. startSecond: 7.259,
  200. text: " ",
  201. },
  202. {
  203. endSecond: 7.759,
  204. startSecond: 7.699,
  205. text: "or",
  206. },
  207. {
  208. endSecond: 7.859,
  209. startSecond: 7.759,
  210. text: " ",
  211. },
  212. {
  213. endSecond: 8.739,
  214. startSecond: 7.859,
  215. text: "micro-frontends",
  216. },
  217. {
  218. endSecond: 8.78,
  219. startSecond: 8.739,
  220. text: " ",
  221. },
  222. {
  223. endSecond: 8.96,
  224. startSecond: 8.78,
  225. text: "to",
  226. },
  227. {
  228. endSecond: 9.099,
  229. startSecond: 8.96,
  230. text: " ",
  231. },
  232. {
  233. endSecond: 9.779,
  234. startSecond: 9.099,
  235. text: "AI-powered",
  236. },
  237. {
  238. endSecond: 9.82,
  239. startSecond: 9.779,
  240. text: " ",
  241. },
  242. {
  243. endSecond: 10.439,
  244. startSecond: 9.82,
  245. text: "agents.",
  246. },
  247. ];
  248. const Example = () => {
  249. const audioRef = useRef<HTMLAudioElement>(null);
  250. const [currentTime, setCurrentTime] = useState(0);
  251. const handleSeek = useCallback((time: number) => {
  252. if (audioRef.current) {
  253. audioRef.current.currentTime = time;
  254. }
  255. }, []);
  256. const handleTimeUpdate = useCallback(() => {
  257. if (audioRef.current) {
  258. setCurrentTime(audioRef.current.currentTime);
  259. }
  260. }, []);
  261. return (
  262. <div className="space-y-6 p-6">
  263. {/* biome-ignore lint/a11y/useMediaCaption: "No caption needed" */}
  264. {/* oxlint-disable-next-line eslint-plugin-jsx-a11y(media-has-caption) */}
  265. <audio controls onTimeUpdate={handleTimeUpdate} ref={audioRef}>
  266. <source src="https://ejiidnob33g9ap1r.public.blob.vercel-storage.com/ElevenLabs_2025-11-10T22_10_24_Hayden_pvc_sp110_s50_sb75_se0_b_m2.mp3" />
  267. </audio>
  268. <Transcription currentTime={currentTime} onSeek={handleSeek} segments={segments}>
  269. {(segment, index) => (
  270. <TranscriptionSegment
  271. className="text-lg"
  272. index={index}
  273. key={`${segment.startSecond}-${segment.endSecond}`}
  274. segment={segment}
  275. />
  276. )}
  277. </Transcription>
  278. </div>
  279. );
  280. };
  281. export default Example;