|
5 | 5 | "io" |
6 | 6 | "net/http" |
7 | 7 | "net/url" |
| 8 | + "strings" |
8 | 9 | "time" |
9 | 10 | ) |
10 | 11 |
|
@@ -70,20 +71,24 @@ const ( |
70 | 71 | VoiceAPI = "https://genshin.azurewebsites.net/api/speak?format=wav&text=%s&id=%d" |
71 | 72 | ) |
72 | 73 |
|
73 | | -var client = &http.Client{Timeout: time.Second * 30} |
| 74 | +var client = &http.Client{Timeout: time.Second * 300} |
74 | 75 |
|
75 | 76 | func GetGenshinVoice(msg, actor string) ([]byte, error) { |
76 | 77 | if id, ok := actors[actor]; !ok { |
77 | 78 | return nil, fmt.Errorf("未知的角色: %s", actor) |
78 | 79 | } else { |
79 | | - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf(VoiceAPI, url.QueryEscape(msg), id), nil) |
| 80 | + api := fmt.Sprintf(VoiceAPI, url.QueryEscape(msg), id) |
| 81 | + req, err := http.NewRequest(http.MethodGet, api, nil) |
80 | 82 | if err != nil { |
81 | 83 | return nil, fmt.Errorf("http_error: %v", err) |
82 | 84 | } |
83 | 85 | req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36") |
84 | 86 | res, err := client.Do(req) |
85 | 87 | if err != nil { |
86 | | - return nil, fmt.Errorf("http_error: %v", err) |
| 88 | + if strings.Contains(err.Error(), "context deadline exceeded") { |
| 89 | + return nil, fmt.Errorf("http_error: %s", "API请求逾时") |
| 90 | + } |
| 91 | + return nil, fmt.Errorf("http_error: %v", err.Error()) |
87 | 92 | } |
88 | 93 | defer res.Body.Close() |
89 | 94 | if res.StatusCode != 200 { |
|
0 commit comments