dlxj commited on
Commit
2c13ec2
·
1 Parent(s): 2a42479
Files changed (2) hide show
  1. KotobaASRLLM_Cuda130/post.py +42 -0
  2. post.py +1 -1
KotobaASRLLM_Cuda130/post.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import os
4
+
5
+ url = "http://127.0.0.1:8969/inference"
6
+
7
+ # 音频文件路径,根据 readme.txt #L23,这里以 60s.wav 为例
8
+ # 使用相对路径
9
+ script_dir = os.path.dirname(os.path.abspath(__file__))
10
+ audio_file = os.path.join(script_dir, "60s.wav")
11
+
12
+ if not os.path.exists(audio_file):
13
+ print(f"找不到音频文件: {audio_file}")
14
+ exit(1)
15
+
16
+ # 构建 multipart/form-data 数据
17
+ # 使用 language = ja,对应 -l ja
18
+ # response_format 设为 json,对应 --output-json
19
+ data = {
20
+ "temperature": "0.0",
21
+ "language": "ja",
22
+ "response_format": "json"
23
+ }
24
+
25
+ print(f"正在发送请求到 {url}...")
26
+ print(f"音频文件: {audio_file}")
27
+
28
+ with open(audio_file, "rb") as f:
29
+ files = {"file": (os.path.basename(audio_file), f, "audio/wav")}
30
+ try:
31
+ response = requests.post(url, data=data, files=files)
32
+ response.raise_for_status()
33
+
34
+ # 尝试解析返回的 JSON 数据
35
+ result = response.json()
36
+ print("\n识别结果 (JSON格式):")
37
+ print(json.dumps(result, indent=2, ensure_ascii=False))
38
+
39
+ except requests.exceptions.RequestException as e:
40
+ print(f"\n请求失败: {e}")
41
+ if e.response is not None:
42
+ print(f"服务器返回内容: {e.response.text}")
post.py CHANGED
@@ -7,7 +7,7 @@ url = "http://127.0.0.1:8969/inference"
7
  # 音频文件路径,根据 readme.txt #L23,这里以 60s.wav 为例
8
  # 使用相对路径
9
  script_dir = os.path.dirname(os.path.abspath(__file__))
10
- audio_file = os.path.join(script_dir, "KotobaASRLLM", "60s.wav")
11
 
12
  if not os.path.exists(audio_file):
13
  print(f"找不到音频文件: {audio_file}")
 
7
  # 音频文件路径,根据 readme.txt #L23,这里以 60s.wav 为例
8
  # 使用相对路径
9
  script_dir = os.path.dirname(os.path.abspath(__file__))
10
+ audio_file = os.path.join(script_dir, "KotobaASRLLM_Cuda130", "60s.wav")
11
 
12
  if not os.path.exists(audio_file):
13
  print(f"找不到音频文件: {audio_file}")