realtime-config.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { RealtimeConfig } from "@/app/store";
  2. import Locale from "@/app/locales";
  3. import { ListItem, Select, PasswordInput } from "@/app/components/ui-lib";
  4. import { InputRange } from "@/app/components/input-range";
  5. import { Voice } from "rt-client";
  6. import { ServiceProvider } from "@/app/constant";
  7. const providers = [ServiceProvider.OpenAI, ServiceProvider.Azure];
  8. const models = ["gpt-4o-realtime-preview-2024-10-01"];
  9. const voice = ["alloy", "shimmer", "echo"];
  10. export function RealtimeConfigList(props: {
  11. realtimeConfig: RealtimeConfig;
  12. updateConfig: (updater: (config: RealtimeConfig) => void) => void;
  13. }) {
  14. const azureConfigComponent = props.realtimeConfig.provider ===
  15. ServiceProvider.Azure && (
  16. <>
  17. <ListItem
  18. title={Locale.Settings.Realtime.Azure.Endpoint.Title}
  19. subTitle={Locale.Settings.Realtime.Azure.Endpoint.SubTitle}
  20. >
  21. <input
  22. value={props.realtimeConfig?.azure?.endpoint}
  23. type="text"
  24. placeholder={Locale.Settings.Realtime.Azure.Endpoint.Title}
  25. onChange={(e) => {
  26. props.updateConfig(
  27. (config) => (config.azure.endpoint = e.currentTarget.value),
  28. );
  29. }}
  30. />
  31. </ListItem>
  32. <ListItem
  33. title={Locale.Settings.Realtime.Azure.Deployment.Title}
  34. subTitle={Locale.Settings.Realtime.Azure.Deployment.SubTitle}
  35. >
  36. <input
  37. value={props.realtimeConfig?.azure?.deployment}
  38. type="text"
  39. placeholder={Locale.Settings.Realtime.Azure.Deployment.Title}
  40. onChange={(e) => {
  41. props.updateConfig(
  42. (config) => (config.azure.deployment = e.currentTarget.value),
  43. );
  44. }}
  45. />
  46. </ListItem>
  47. </>
  48. );
  49. return (
  50. <>
  51. <ListItem
  52. title={Locale.Settings.Realtime.Enable.Title}
  53. subTitle={Locale.Settings.Realtime.Enable.SubTitle}
  54. >
  55. <input
  56. type="checkbox"
  57. checked={props.realtimeConfig.enable}
  58. onChange={(e) =>
  59. props.updateConfig(
  60. (config) => (config.enable = e.currentTarget.checked),
  61. )
  62. }
  63. ></input>
  64. </ListItem>
  65. {props.realtimeConfig.enable && (
  66. <>
  67. <ListItem
  68. title={Locale.Settings.Realtime.Provider.Title}
  69. subTitle={Locale.Settings.Realtime.Provider.SubTitle}
  70. >
  71. <Select
  72. aria-label={Locale.Settings.Realtime.Provider.Title}
  73. value={props.realtimeConfig.provider}
  74. onChange={(e) => {
  75. props.updateConfig(
  76. (config) =>
  77. (config.provider = e.target.value as ServiceProvider),
  78. );
  79. }}
  80. >
  81. {providers.map((v, i) => (
  82. <option value={v} key={i}>
  83. {v}
  84. </option>
  85. ))}
  86. </Select>
  87. </ListItem>
  88. <ListItem
  89. title={Locale.Settings.Realtime.Model.Title}
  90. subTitle={Locale.Settings.Realtime.Model.SubTitle}
  91. >
  92. <Select
  93. aria-label={Locale.Settings.Realtime.Model.Title}
  94. value={props.realtimeConfig.model}
  95. onChange={(e) => {
  96. props.updateConfig((config) => (config.model = e.target.value));
  97. }}
  98. >
  99. {models.map((v, i) => (
  100. <option value={v} key={i}>
  101. {v}
  102. </option>
  103. ))}
  104. </Select>
  105. </ListItem>
  106. <ListItem
  107. title={Locale.Settings.Realtime.ApiKey.Title}
  108. subTitle={Locale.Settings.Realtime.ApiKey.SubTitle}
  109. >
  110. <PasswordInput
  111. aria={Locale.Settings.ShowPassword}
  112. aria-label={Locale.Settings.Realtime.ApiKey.Title}
  113. value={props.realtimeConfig.apiKey}
  114. type="text"
  115. placeholder={Locale.Settings.Realtime.ApiKey.Placeholder}
  116. onChange={(e) => {
  117. props.updateConfig(
  118. (config) => (config.apiKey = e.currentTarget.value),
  119. );
  120. }}
  121. />
  122. </ListItem>
  123. {azureConfigComponent}
  124. <ListItem
  125. title={Locale.Settings.TTS.Voice.Title}
  126. subTitle={Locale.Settings.TTS.Voice.SubTitle}
  127. >
  128. <Select
  129. value={props.realtimeConfig.voice}
  130. onChange={(e) => {
  131. props.updateConfig(
  132. (config) => (config.voice = e.currentTarget.value as Voice),
  133. );
  134. }}
  135. >
  136. {voice.map((v, i) => (
  137. <option value={v} key={i}>
  138. {v}
  139. </option>
  140. ))}
  141. </Select>
  142. </ListItem>
  143. <ListItem
  144. title={Locale.Settings.Realtime.Temperature.Title}
  145. subTitle={Locale.Settings.Realtime.Temperature.SubTitle}
  146. >
  147. <InputRange
  148. aria={Locale.Settings.Temperature.Title}
  149. value={props.realtimeConfig?.temperature?.toFixed(1)}
  150. min="0.6"
  151. max="1"
  152. step="0.1"
  153. onChange={(e) => {
  154. props.updateConfig(
  155. (config) =>
  156. (config.temperature = e.currentTarget.valueAsNumber),
  157. );
  158. }}
  159. ></InputRange>
  160. </ListItem>
  161. </>
  162. )}
  163. </>
  164. );
  165. }