[C#] 纯文本查看 复制代码 using Baidu.Aip.Speech;
using Newtonsoft.Json.Linq;
using System.IO;
using NAudio.Wave;
using System;
using Newtonsoft.Json;
using System.Text.Json.Nodes;
using System.Collections.Generic;
namespace speechVolume
{
public partial class Form1 : Form
{
private static string fileName = "volume";
private static string fileType = "wav";
private static string wavName = "001." + fileType;
private static string path = Application.StartupPath;
private static string path1 = path + fileName;
private static string path2 = path1 + "\\";
private static string filePath = path2 + wavName;
private static NAudioTool nt = new NAudioTool();
public Form1()
{
InitializeComponent();
initialize();
}
public void initialize()
{
// 创建本地录音文件
textBox1.Text = filePath;
if (!Directory.Exists(path1))
{
Directory.CreateDirectory(path1);
}
if (!File.Exists(filePath))
{
File.Create(filePath).Close();
}
// 音频地址
nt.setSavePath(filePath);
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text.Equals("开"))
{
button1.Text = "关";
nt.StartRecordAudio();
}
else
{
button1.Text = "开";
nt.StopRecordAudio();
}
}
public void readWav()
{
// 设置APPID/AK/SK
string APP_ID = "37429179";
string API_KEY = "Pvg5bSGwkY3ef5Uuo61PpE7c";
string SECRET_KEY = "dg956md7g4d1nH55Wvs5XA664f9McxV8";
// 语音识别最长60秒
Asr asr = new Asr(APP_ID, API_KEY, SECRET_KEY) { Timeout = 60000 };
// 录音数据
byte[] data = File.ReadAllBytes(filePath);
// 额外参数
Dictionary<string, object> options = new Dictionary<string, object>
{
{"dev_pid", 1537} //语音模型1537普通话
};
//数据上传,wav格式,16000码率,额外数据
JObject result = asr.RecognizePro(data, "wav", 16000, 1537, options);
Console.Write(result);
this.textBox3.Text = result.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
readWav();
}
}
}
实在是不知道到底改什么了,一直报错: "err_msg": "110: Access token invalid or no longer valid"
|