Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Voice Test with Java

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use Java to achieve voice testing". In daily operation, I believe many people have doubts about how to use Java to achieve voice testing. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use Java to achieve voice testing". Next, please follow the editor to study!

I recorded a note and stored it in this test.m4a file, which read "Test Netweaver's response to concurrent requests".

Test with the following Java code:

Package com.iflytek.msp.lfasr;import java.util.HashMap;import org.apache.log4j.Logger;import com.alibaba.fastjson.JSON;import com.iflytek.msp.cpdb.lfasr.client.LfasrClientImp;import com.iflytek.msp.cpdb.lfasr.exception.LfasrException;import com.iflytek.msp.cpdb.lfasr.model.LfasrType;import com.iflytek.msp.cpdb.lfasr.model.Message;import com.iflytek.msp.cpdb.lfasr.model.ProgressStatus / / SDK document: http://www.xfyun.cn/doccenter/lfasr#go_sdk_doc_v2public class TestLfasr {/ / original media path private static final String local_file = "c:\\ temp\\ test.m4a"; private static final LfasrType type = LfasrType.LFASR_STANDARD_RECORDED_AUDIO; private static int sleepSecond = 20; public static void main (String [] args) {LfasrClientImp lc = null; try {lc = LfasrClientImp.initLfasrClient () } catch (LfasrException e) {Message initMsg = JSON.parseObject (e.getMessage (), Message.class); System.out.println ("ecode=" + initMsg.getErr_no ()); System.out.println ("failed=" + initMsg.getFailed ());} / / get upload task id String task_id = ""; HashMap params = new HashMap () Params.put ("has_participle", "true"); try {Message uploadMsg = lc.lfasrUpload (local_file, type, params); int ok = uploadMsg.getOk (); if (ok = = 0) {task_id= uploadMsg.getData (); System.out.println ("task_id=" + task_id) } else {System.out.println ("ecode=" + uploadMsg.getErr_no ()); System.out.println ("failed=" + uploadMsg.getFailed ());} catch (LfasrException e) {Message uploadMsg = JSON.parseObject (e.getMessage (), Message.class); System.out.println ("ecode=" + uploadMsg.getErr_no ()) System.out.println ("failed=" + uploadMsg.getFailed ());} while (true) {try {Thread.sleep (sleepSecond * 1000); System.out.println ("waiting...") } catch (InterruptedException e) {} try {Message progressMsg = lc.lfasrGetProgress (task_id); if (progressMsg.getOk ()! = 0) {System.out.println ("task was fail. Task_id: "+ task_id); System.out.println (" ecode= "+ progressMsg.getErr_no ()); System.out.println (" failed= "+ progressMsg.getFailed ()); continue;} else {ProgressStatus progressStatus = JSON.parseObject (progressMsg.getData (), ProgressStatus.class) If (progressStatus.getStatus () = = 9) {System.out.println ("task was completed. Task_id: "+ task_id); break;} else {System.out.println (" task was incomplete. Task_id: "+ task_id +", status: "+ progressStatus.getDesc (); continue;} catch (LfasrException e) {Message progressMsg = JSON.parseObject (e.getMessage (), Message.class); System.out.println (" ecode= "+ progressMsg.getErr_no ()) System.out.println ("failed=" + progressMsg.getFailed ());}} try {Message resultMsg = lc.lfasrGetResult (task_id); System.out.println (resultMsg.getData ()); if (resultMsg.getOk () = = 0) {System.out.println (resultMsg.getData ()) } else {System.out.println ("ecode=" + resultMsg.getErr_no ()); System.out.println ("failed=" + resultMsg.getFailed ());} catch (LfasrException e) {Message resultMsg = JSON.parseObject (e.getMessage (), Message.class); System.out.println ("ecode=" + resultMsg.getErr_no ()) System.out.println ("failed=" + resultMsg.getFailed ());} Test results

(1) all Chinese can be converted into text successfully, but the voice of English Netweaver has been converted into Net ball.

(2) Intelligent word segmentation can also work as expected, for example, "test" successfully turns into "test" and "try".

At this point, the study on "how to use Java to achieve voice testing" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report