[英]Some error when get data from HTTP request with post
我按照以下說明進行操作: HTTP請求和發布以從站點獲取音頻文件: http : //www.tudienabc.com/phat-am-tieng-nhat (該站點允許我們輸入英語或日語單詞/短語/句子並生成音頻文件,在回傳后,在HTML代碼的第129行中看起來像“ /pronunciations/audio?file_name=1431134309.002.mp3&file_type=mp3”。
但是,我從自己的應用程序中獲取的音頻文件與從本網站生成的音頻文件不同。 從此網站生成的音頻文件(mp3)可以在www.tudienabc.com/pronunciations/上播放(例如:www.tudienabc.com/pronunciations/audio?file_name=1431141268.9947.mp3&file_type=mp3),但從我的應用程序無法播放(例如:www.tudienabc.com/pronunciations/audio?file_name=1431141475.4908.mp3&file_type=mp3)。
那怎么了 以及如何獲取確切的音頻文件?
這是我的代碼:
var request = (HttpWebRequest)WebRequest.Create("http://www.tudienabc.com/phat-am-tieng-nhat");
var postData = "_method=POST&data[Pronun][text]=hello&data[Pronun][type]=3";
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
int m = responseString.IndexOf("pronunciations/audio?file_name=")+"pronunciations/audio?file_name=".Length;
int n = responseString.IndexOf("&file_type=mp3");
string filename = responseString.Substring(m, n - m);
return filename;
謝謝,
他們的網站使用ECMAScript處理音頻
<script>
var wait = new waitGenerateAudio(
'#progress_audio_placeholder',
'/pronunciations/checkFinish/1431151184.739',
'aGVsbG8gZnlyeWU=',
'/pronunciations/audio?file_name=1431151184.739.mp3&file_type=mp3',
'T?o file l?i'
);
</script>
您將需要能夠處理要創建的音頻文件的JavaScript。
結帳C#httpwebrequest和javascript或WebClient運行javascript
用於利用無頭瀏覽器。
我建議尋找一個功能更豐富的庫,用於文本到音頻。 https://gist.github.com/alotaiba/1728771
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.