88use OpenAI \Responses \Concerns \ArrayAccessible ;
99
1010/**
11- * @implements ResponseContract<array{id: int, seek: int, start: float, end: float, text: string, tokens: array<int, int>, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient?: bool}>
11+ * @implements ResponseContract<array{id: int|string, start: float, end: float, text: string, seek?: int, tokens? : array<int, int>, temperature? : float, avg_logprob? : float, compression_ratio? : float, no_speech_prob? : float, transient?: bool, speaker?: string, type?: string }>
1212 */
1313final class TranscriptionResponseSegment implements ResponseContract
1414{
1515 /**
16- * @use ArrayAccessible<array{id: int, seek: int, start: float, end: float, text: string, tokens: array<int, int>, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient?: bool}>
16+ * @use ArrayAccessible<array{id: int|string, start: float, end: float, text: string, seek?: int, tokens? : array<int, int>, temperature? : float, avg_logprob? : float, compression_ratio? : float, no_speech_prob? : float, transient?: bool, speaker?: string, type?: string }>
1717 */
1818 use ArrayAccessible;
1919
2020 /**
21+ * @param int|string $id string in case of diarization, int otherwise
2122 * @param array<int, int> $tokens
2223 */
2324 private function __construct (
24- public readonly int $ id ,
25- public readonly int $ seek ,
25+ public readonly int |string $ id ,
2626 public readonly float $ start ,
2727 public readonly float $ end ,
2828 public readonly string $ text ,
29- public readonly array $ tokens ,
30- public readonly float $ temperature ,
31- public readonly float $ avgLogprob ,
32- public readonly float $ compressionRatio ,
33- public readonly float $ noSpeechProb ,
29+ public readonly ?int $ seek ,
30+ public readonly ?array $ tokens ,
31+ public readonly ?float $ temperature ,
32+ public readonly ?float $ avgLogprob ,
33+ public readonly ?float $ compressionRatio ,
34+ public readonly ?float $ noSpeechProb ,
3435 public readonly ?bool $ transient ,
36+ public readonly ?string $ speaker ,
37+ public readonly ?string $ type ,
3538 ) {}
3639
3740 /**
3841 * Acts as static factory, and returns a new Response instance.
3942 *
40- * @param array{id: int, seek: int, start: float, end: float, text: string, tokens: array<int, int>, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient?: bool} $attributes
43+ * @param array{id: int|string, start: float, end: float, text: string, seek?: int, tokens? : array<int, int>, temperature? : float, avg_logprob? : float, compression_ratio? : float, no_speech_prob? : float, transient?: bool, speaker?: string, type?: string } $attributes
4144 */
4245 public static function from (array $ attributes ): self
4346 {
4447 return new self (
4548 $ attributes ['id ' ],
46- $ attributes ['seek ' ],
4749 $ attributes ['start ' ],
4850 $ attributes ['end ' ],
4951 $ attributes ['text ' ],
50- $ attributes ['tokens ' ],
51- $ attributes ['temperature ' ],
52- $ attributes ['avg_logprob ' ],
53- $ attributes ['compression_ratio ' ],
54- $ attributes ['no_speech_prob ' ],
52+ $ attributes ['seek ' ] ?? null ,
53+ $ attributes ['tokens ' ] ?? null ,
54+ $ attributes ['temperature ' ] ?? null ,
55+ $ attributes ['avg_logprob ' ] ?? null ,
56+ $ attributes ['compression_ratio ' ] ?? null ,
57+ $ attributes ['no_speech_prob ' ] ?? null ,
5558 $ attributes ['transient ' ] ?? null ,
59+ $ attributes ['speaker ' ] ?? null ,
60+ $ attributes ['type ' ] ?? null ,
5661 );
5762 }
5863
@@ -63,21 +68,47 @@ public function toArray(): array
6368 {
6469 $ data = [
6570 'id ' => $ this ->id ,
66- 'seek ' => $ this ->seek ,
6771 'start ' => $ this ->start ,
6872 'end ' => $ this ->end ,
6973 'text ' => $ this ->text ,
70- 'tokens ' => $ this ->tokens ,
71- 'temperature ' => $ this ->temperature ,
72- 'avg_logprob ' => $ this ->avgLogprob ,
73- 'compression_ratio ' => $ this ->compressionRatio ,
74- 'no_speech_prob ' => $ this ->noSpeechProb ,
7574 ];
7675
76+ if ($ this ->seek !== null ) {
77+ $ data ['seek ' ] = $ this ->seek ;
78+ }
79+
80+ if ($ this ->tokens !== null ) {
81+ $ data ['tokens ' ] = $ this ->tokens ;
82+ }
83+
84+ if ($ this ->temperature !== null ) {
85+ $ data ['temperature ' ] = $ this ->temperature ;
86+ }
87+
88+ if ($ this ->avgLogprob !== null ) {
89+ $ data ['avg_logprob ' ] = $ this ->avgLogprob ;
90+ }
91+
92+ if ($ this ->compressionRatio !== null ) {
93+ $ data ['compression_ratio ' ] = $ this ->compressionRatio ;
94+ }
95+
96+ if ($ this ->noSpeechProb !== null ) {
97+ $ data ['no_speech_prob ' ] = $ this ->noSpeechProb ;
98+ }
99+
77100 if ($ this ->transient !== null ) {
78101 $ data ['transient ' ] = $ this ->transient ;
79102 }
80103
104+ if ($ this ->speaker !== null ) {
105+ $ data ['speaker ' ] = $ this ->speaker ;
106+ }
107+
108+ if ($ this ->type !== null ) {
109+ $ data ['type ' ] = $ this ->type ;
110+ }
111+
81112 return $ data ;
82113 }
83114}
0 commit comments