mirror of
https://github.com/openai/whisper.git
synced 2025-07-04 11:12:29 +00:00
Merge 3d126013d7005bd23fef116fe4466246ed0d5296 into 517a43ecd132a2089d85f4ebc044728a71d49f6e
This commit is contained in:
commit
88fb1e13da
@ -3,7 +3,8 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import zlib
|
import zlib
|
||||||
from typing import Callable, List, Optional, TextIO
|
from pathlib import Path
|
||||||
|
from typing import Callable, List, Optional, TextIO, Union
|
||||||
|
|
||||||
system_encoding = sys.getdefaultencoding()
|
system_encoding = sys.getdefaultencoding()
|
||||||
|
|
||||||
@ -89,16 +90,21 @@ class ResultWriter:
|
|||||||
self.output_dir = output_dir
|
self.output_dir = output_dir
|
||||||
|
|
||||||
def __call__(
|
def __call__(
|
||||||
self, result: dict, audio_path: str, options: Optional[dict] = None, **kwargs
|
self,
|
||||||
):
|
result: dict,
|
||||||
audio_basename = os.path.basename(audio_path)
|
audio_path: Union[str, Path],
|
||||||
audio_basename = os.path.splitext(audio_basename)[0]
|
options: Optional[dict] = None,
|
||||||
|
**kwargs,
|
||||||
|
) -> str:
|
||||||
|
if not isinstance(audio_path, Path):
|
||||||
|
audio_path = Path(audio_path)
|
||||||
output_path = os.path.join(
|
output_path = os.path.join(
|
||||||
self.output_dir, audio_basename + "." + self.extension
|
self.output_dir, audio_path.with_suffix(self.extension).name
|
||||||
)
|
)
|
||||||
|
|
||||||
with open(output_path, "w", encoding="utf-8") as f:
|
with open(output_path, "w", encoding="utf-8") as f:
|
||||||
self.write_result(result, file=f, options=options, **kwargs)
|
self.write_result(result, file=f, options=options, **kwargs)
|
||||||
|
return output_path
|
||||||
|
|
||||||
def write_result(
|
def write_result(
|
||||||
self, result: dict, file: TextIO, options: Optional[dict] = None, **kwargs
|
self, result: dict, file: TextIO, options: Optional[dict] = None, **kwargs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user