Unclosed resource in \Drupal\ai\Base\OpenAiBasedProviderClientBase::speechToText()
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3558536. -->
Reported by: [mxr576](https://www.drupal.org/user/315522)
Related to !1020
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>A resource is opened in <code>\Drupal\ai\Base\OpenAiBasedProviderClientBase::speechToText()</code>.</p>
<pre> $path = $this->fileSystem->saveData($input, 'temporary://speech_to_text.mp3', FileExists::Replace);<br> $input = fopen($path, 'r');<br><br> $payload = [<br> 'model' => $model_id,<br> 'file' => $input,<br> ] + $this->configuration;<br><br> try {<br> $response = $this->client->audio()->transcribe($payload)->toArray();<br> return new SpeechToTextOutput($response['text'], $response, []);<br> }<br> catch (\Exception $e) {<br> $this->handleApiException($e);<br> throw $e;<br> }</pre><h4 id="summary-steps-reproduce">Steps to reproduce (required for bugs, but not feature requests)</h4>
<p>Please provide information like AI modules enabled, which AI provider, browser, etc.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Close the resource when the operation is done or an error occured.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<h3>Optional: Other details as applicable (e.g., User interface changes, API changes, Data model changes)</h3>
issue