-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add `/v1/audio/transcriptions` api - support whisper model - add stt tests
- Loading branch information
Showing
9 changed files
with
179 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import argparse | ||
|
||
import soundfile as sf | ||
|
||
from modules.core.spk.TTSSpeaker import TTSSpeaker | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description="Edit TTSSpeaker data") | ||
parser.add_argument( | ||
"--spk", | ||
required=True, | ||
help="Speaker file path", | ||
) | ||
parser.add_argument( | ||
"--out", | ||
required=True, | ||
help="Output file path", | ||
) | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
if __name__ == "__main__": | ||
""" | ||
此脚本用于检查 spk 文件的 wav 音频信息 | ||
NOTE: 暂时只检查第一个,后续补充其他参数 | ||
""" | ||
args = parse_args() | ||
|
||
spk = TTSSpeaker.from_file(args.spk) | ||
|
||
sr, wav, text = spk.get_ref_wav() | ||
|
||
print(f"{wav.shape[0] / sr} seconds") | ||
print(f"{wav.shape[0]} samples") | ||
print(f"{sr} kz") | ||
print(f"Text: {text}") | ||
|
||
sf.write(args.out, wav, sr * 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
|
||
|
||
@pytest.mark.openai_api_stt | ||
def test_openai_speech_api_with_invalid_style(client: TestClient): | ||
file_path = "./tests/test_inputs/cosyvoice_out1.wav" | ||
|
||
with open(file_path, "rb") as file: | ||
response = client.post( | ||
"/v1/audio/transcriptions", | ||
files={"file": (file_path, file, "audio/wav")}, | ||
data={ | ||
"model": "whisper.large", | ||
"language": "zh", | ||
"prompt": "", | ||
"response_format": "txt", | ||
"temperature": 0, | ||
"timestamp_granularities": "segment", | ||
}, | ||
) | ||
|
||
assert response.status_code == 200 | ||
response_data = response.json() | ||
assert isinstance(response_data["text"], str) | ||
expected_text = "我们走的每一步都是我们策略的一部分\n你看到的所有一切\n包括我此刻与你交谈\n所做的一切\n所说的每一句话\n都有深远的含义\n" | ||
assert response_data["text"] == expected_text |
Binary file not shown.