Commit 4cb0fd25 by zhengcheng.wang

Initial commit

parents
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/gRPC-Raisound-Base-second-pass.iml" filepath="$PROJECT_DIR$/.idea/gRPC-Raisound-Base-second-pass.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/command.sql" dialect="MariaDB" />
<file url="file://$PROJECT_DIR$/log.sql" dialect="MariaDB" />
</component>
</project>
\ No newline at end of file
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1-devel
// protoc v3.19.1
// source: Raisound-protobuf/raisound.proto
package raisound
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// 初始化语音流的设置
type InitConfig struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"`
Devid string `protobuf:"bytes,2,opt,name=devid,proto3" json:"devid,omitempty"`
Codec string `protobuf:"bytes,3,opt,name=codec,proto3" json:"codec,omitempty"`
SampleRate int32 `protobuf:"varint,4,opt,name=sample_rate,json=sampleRate,proto3" json:"sample_rate,omitempty"`
SampleBits int32 `protobuf:"varint,5,opt,name=sample_bits,json=sampleBits,proto3" json:"sample_bits,omitempty"`
Bitrate int32 `protobuf:"varint,6,opt,name=bitrate,proto3" json:"bitrate,omitempty"`
Scene string `protobuf:"bytes,7,opt,name=scene,proto3" json:"scene,omitempty"`
Lang string `protobuf:"bytes,8,opt,name=lang,proto3" json:"lang,omitempty"`
Nbest int32 `protobuf:"varint,9,opt,name=nbest,proto3" json:"nbest,omitempty"`
VadLevel int32 `protobuf:"varint,10,opt,name=vad_level,json=vadLevel,proto3" json:"vad_level,omitempty"`
MaxSpeechDuration int32 `protobuf:"varint,11,opt,name=max_speech_duration,json=maxSpeechDuration,proto3" json:"max_speech_duration,omitempty"`
MeetingId string `protobuf:"bytes,12,opt,name=meeting_id,json=meetingId,proto3" json:"meeting_id,omitempty"`
AppName string `protobuf:"bytes,13,opt,name=app_name,json=appName,proto3" json:"app_name,omitempty"`
ConnId string `protobuf:"bytes,14,opt,name=conn_id,json=connId,proto3" json:"conn_id,omitempty"`
OralFlag bool `protobuf:"varint,15,opt,name=oral_flag,json=oralFlag,proto3" json:"oral_flag,omitempty"`
SensitiveFlag bool `protobuf:"varint,16,opt,name=sensitive_flag,json=sensitiveFlag,proto3" json:"sensitive_flag,omitempty"`
PuncFlag bool `protobuf:"varint,17,opt,name=punc_flag,json=puncFlag,proto3" json:"punc_flag,omitempty"`
NumConvertFlag bool `protobuf:"varint,18,opt,name=num_convert_flag,json=numConvertFlag,proto3" json:"num_convert_flag,omitempty"`
User string `protobuf:"bytes,19,opt,name=user,proto3" json:"user,omitempty"`
Passwd string `protobuf:"bytes,20,opt,name=passwd,proto3" json:"passwd,omitempty"`
InterOuterFlag int32 `protobuf:"varint,21,opt,name=inter_outer_flag,json=interOuterFlag,proto3" json:"inter_outer_flag,omitempty"` //0表示对内,1表示对外
}
func (x *InitConfig) Reset() {
*x = InitConfig{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InitConfig) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InitConfig) ProtoMessage() {}
func (x *InitConfig) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use InitConfig.ProtoReflect.Descriptor instead.
func (*InitConfig) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{0}
}
func (x *InitConfig) GetToken() string {
if x != nil {
return x.Token
}
return ""
}
func (x *InitConfig) GetDevid() string {
if x != nil {
return x.Devid
}
return ""
}
func (x *InitConfig) GetCodec() string {
if x != nil {
return x.Codec
}
return ""
}
func (x *InitConfig) GetSampleRate() int32 {
if x != nil {
return x.SampleRate
}
return 0
}
func (x *InitConfig) GetSampleBits() int32 {
if x != nil {
return x.SampleBits
}
return 0
}
func (x *InitConfig) GetBitrate() int32 {
if x != nil {
return x.Bitrate
}
return 0
}
func (x *InitConfig) GetScene() string {
if x != nil {
return x.Scene
}
return ""
}
func (x *InitConfig) GetLang() string {
if x != nil {
return x.Lang
}
return ""
}
func (x *InitConfig) GetNbest() int32 {
if x != nil {
return x.Nbest
}
return 0
}
func (x *InitConfig) GetVadLevel() int32 {
if x != nil {
return x.VadLevel
}
return 0
}
func (x *InitConfig) GetMaxSpeechDuration() int32 {
if x != nil {
return x.MaxSpeechDuration
}
return 0
}
func (x *InitConfig) GetMeetingId() string {
if x != nil {
return x.MeetingId
}
return ""
}
func (x *InitConfig) GetAppName() string {
if x != nil {
return x.AppName
}
return ""
}
func (x *InitConfig) GetConnId() string {
if x != nil {
return x.ConnId
}
return ""
}
func (x *InitConfig) GetOralFlag() bool {
if x != nil {
return x.OralFlag
}
return false
}
func (x *InitConfig) GetSensitiveFlag() bool {
if x != nil {
return x.SensitiveFlag
}
return false
}
func (x *InitConfig) GetPuncFlag() bool {
if x != nil {
return x.PuncFlag
}
return false
}
func (x *InitConfig) GetNumConvertFlag() bool {
if x != nil {
return x.NumConvertFlag
}
return false
}
func (x *InitConfig) GetUser() string {
if x != nil {
return x.User
}
return ""
}
func (x *InitConfig) GetPasswd() string {
if x != nil {
return x.Passwd
}
return ""
}
func (x *InitConfig) GetInterOuterFlag() int32 {
if x != nil {
return x.InterOuterFlag
}
return 0
}
// 初始化语音流的返回
type InitResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
}
func (x *InitResponse) Reset() {
*x = InitResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InitResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InitResponse) ProtoMessage() {}
func (x *InitResponse) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use InitResponse.ProtoReflect.Descriptor instead.
func (*InitResponse) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{1}
}
func (x *InitResponse) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *InitResponse) GetSessionId() string {
if x != nil {
return x.SessionId
}
return ""
}
func (x *InitResponse) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
// 发送语音流数据的设置
type SendAudioConfig struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
AudioData []byte `protobuf:"bytes,2,opt,name=audio_data,json=audioData,proto3" json:"audio_data,omitempty"`
EndFlag int32 `protobuf:"varint,3,opt,name=end_flag,json=endFlag,proto3" json:"end_flag,omitempty"`
DataCount int32 `protobuf:"varint,4,opt,name=data_count,json=dataCount,proto3" json:"data_count,omitempty"`
}
func (x *SendAudioConfig) Reset() {
*x = SendAudioConfig{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SendAudioConfig) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SendAudioConfig) ProtoMessage() {}
func (x *SendAudioConfig) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SendAudioConfig.ProtoReflect.Descriptor instead.
func (*SendAudioConfig) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{2}
}
func (x *SendAudioConfig) GetSessionId() string {
if x != nil {
return x.SessionId
}
return ""
}
func (x *SendAudioConfig) GetAudioData() []byte {
if x != nil {
return x.AudioData
}
return nil
}
func (x *SendAudioConfig) GetEndFlag() int32 {
if x != nil {
return x.EndFlag
}
return 0
}
func (x *SendAudioConfig) GetDataCount() int32 {
if x != nil {
return x.DataCount
}
return 0
}
// 发送语音流的返回
type SendAudioResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
IsResult bool `protobuf:"varint,2,opt,name=is_result,json=isResult,proto3" json:"is_result,omitempty"`
IsFinal bool `protobuf:"varint,3,opt,name=is_final,json=isFinal,proto3" json:"is_final,omitempty"`
SessionId string `protobuf:"bytes,4,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
Results string `protobuf:"bytes,5,opt,name=results,proto3" json:"results,omitempty"`
Description string `protobuf:"bytes,6,opt,name=description,proto3" json:"description,omitempty"`
JsonData string `protobuf:"bytes,7,opt,name=json_data,json=jsonData,proto3" json:"json_data,omitempty"`
SpeechDuration int32 `protobuf:"varint,8,opt,name=speech_duration,json=speechDuration,proto3" json:"speech_duration,omitempty"`
DataIndex int32 `protobuf:"varint,9,opt,name=data_index,json=dataIndex,proto3" json:"data_index,omitempty"`
}
func (x *SendAudioResponse) Reset() {
*x = SendAudioResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SendAudioResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SendAudioResponse) ProtoMessage() {}
func (x *SendAudioResponse) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SendAudioResponse.ProtoReflect.Descriptor instead.
func (*SendAudioResponse) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{3}
}
func (x *SendAudioResponse) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *SendAudioResponse) GetIsResult() bool {
if x != nil {
return x.IsResult
}
return false
}
func (x *SendAudioResponse) GetIsFinal() bool {
if x != nil {
return x.IsFinal
}
return false
}
func (x *SendAudioResponse) GetSessionId() string {
if x != nil {
return x.SessionId
}
return ""
}
func (x *SendAudioResponse) GetResults() string {
if x != nil {
return x.Results
}
return ""
}
func (x *SendAudioResponse) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
func (x *SendAudioResponse) GetJsonData() string {
if x != nil {
return x.JsonData
}
return ""
}
func (x *SendAudioResponse) GetSpeechDuration() int32 {
if x != nil {
return x.SpeechDuration
}
return 0
}
func (x *SendAudioResponse) GetDataIndex() int32 {
if x != nil {
return x.DataIndex
}
return 0
}
// 发送心跳的设置
type HeartBeatConfig struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
}
func (x *HeartBeatConfig) Reset() {
*x = HeartBeatConfig{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HeartBeatConfig) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HeartBeatConfig) ProtoMessage() {}
func (x *HeartBeatConfig) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HeartBeatConfig.ProtoReflect.Descriptor instead.
func (*HeartBeatConfig) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{4}
}
func (x *HeartBeatConfig) GetSessionId() string {
if x != nil {
return x.SessionId
}
return ""
}
// 发送心跳的返回
type HeartBeatResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
}
func (x *HeartBeatResponse) Reset() {
*x = HeartBeatResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HeartBeatResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HeartBeatResponse) ProtoMessage() {}
func (x *HeartBeatResponse) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HeartBeatResponse.ProtoReflect.Descriptor instead.
func (*HeartBeatResponse) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{5}
}
func (x *HeartBeatResponse) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *HeartBeatResponse) GetSessionId() string {
if x != nil {
return x.SessionId
}
return ""
}
func (x *HeartBeatResponse) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
// 释放语音流的设置
type RelConfig struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
}
func (x *RelConfig) Reset() {
*x = RelConfig{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *RelConfig) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RelConfig) ProtoMessage() {}
func (x *RelConfig) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[6]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RelConfig.ProtoReflect.Descriptor instead.
func (*RelConfig) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{6}
}
func (x *RelConfig) GetSessionId() string {
if x != nil {
return x.SessionId
}
return ""
}
// 释放语音流的返回
type RelResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
}
func (x *RelResponse) Reset() {
*x = RelResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *RelResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*RelResponse) ProtoMessage() {}
func (x *RelResponse) ProtoReflect() protoreflect.Message {
mi := &file_Raisound_protobuf_raisound_proto_msgTypes[7]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use RelResponse.ProtoReflect.Descriptor instead.
func (*RelResponse) Descriptor() ([]byte, []int) {
return file_Raisound_protobuf_raisound_proto_rawDescGZIP(), []int{7}
}
func (x *RelResponse) GetCode() int32 {
if x != nil {
return x.Code
}
return 0
}
func (x *RelResponse) GetSessionId() string {
if x != nil {
return x.SessionId
}
return ""
}
func (x *RelResponse) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
var File_Raisound_protobuf_raisound_proto protoreflect.FileDescriptor
var file_Raisound_protobuf_raisound_proto_rawDesc = []byte{
0x0a, 0x20, 0x52, 0x61, 0x69, 0x73, 0x6f, 0x75, 0x6e, 0x64, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2f, 0x72, 0x61, 0x69, 0x73, 0x6f, 0x75, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0xeb, 0x04, 0x0a, 0x0a, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69,
0x67, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x65, 0x76, 0x69, 0x64,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x65, 0x76, 0x69, 0x64, 0x12, 0x14, 0x0a,
0x05, 0x63, 0x6f, 0x64, 0x65, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x63, 0x6f,
0x64, 0x65, 0x63, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x5f, 0x72, 0x61,
0x74, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x52, 0x61, 0x74, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x5f, 0x62,
0x69, 0x74, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x61, 0x6d, 0x70, 0x6c,
0x65, 0x42, 0x69, 0x74, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x69, 0x74, 0x72, 0x61, 0x74, 0x65,
0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x62, 0x69, 0x74, 0x72, 0x61, 0x74, 0x65, 0x12,
0x14, 0x0a, 0x05, 0x73, 0x63, 0x65, 0x6e, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
0x73, 0x63, 0x65, 0x6e, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x61, 0x6e, 0x67, 0x18, 0x08, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x61, 0x6e, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x6e, 0x62, 0x65,
0x73, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6e, 0x62, 0x65, 0x73, 0x74, 0x12,
0x1b, 0x0a, 0x09, 0x76, 0x61, 0x64, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x0a, 0x20, 0x01,
0x28, 0x05, 0x52, 0x08, 0x76, 0x61, 0x64, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x2e, 0x0a, 0x13,
0x6d, 0x61, 0x78, 0x5f, 0x73, 0x70, 0x65, 0x65, 0x63, 0x68, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x6d, 0x61, 0x78, 0x53, 0x70,
0x65, 0x65, 0x63, 0x68, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a,
0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09,
0x52, 0x09, 0x6d, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x61,
0x70, 0x70, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61,
0x70, 0x70, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x6e, 0x5f, 0x69,
0x64, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x63, 0x6f, 0x6e, 0x6e, 0x49, 0x64, 0x12,
0x1b, 0x0a, 0x09, 0x6f, 0x72, 0x61, 0x6c, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x18, 0x0f, 0x20, 0x01,
0x28, 0x08, 0x52, 0x08, 0x6f, 0x72, 0x61, 0x6c, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x25, 0x0a, 0x0e,
0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x18, 0x10,
0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x73, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x69, 0x76, 0x65, 0x46,
0x6c, 0x61, 0x67, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x75, 0x6e, 0x63, 0x5f, 0x66, 0x6c, 0x61, 0x67,
0x18, 0x11, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x70, 0x75, 0x6e, 0x63, 0x46, 0x6c, 0x61, 0x67,
0x12, 0x28, 0x0a, 0x10, 0x6e, 0x75, 0x6d, 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x5f,
0x66, 0x6c, 0x61, 0x67, 0x18, 0x12, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x6e, 0x75, 0x6d, 0x43,
0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73,
0x65, 0x72, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x16,
0x0a, 0x06, 0x70, 0x61, 0x73, 0x73, 0x77, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
0x70, 0x61, 0x73, 0x73, 0x77, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x5f,
0x6f, 0x75, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x6c, 0x61, 0x67, 0x18, 0x15, 0x20, 0x01, 0x28, 0x05,
0x52, 0x0e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x65, 0x72, 0x46, 0x6c, 0x61, 0x67,
0x22, 0x63, 0x0a, 0x0c, 0x49, 0x6e, 0x69, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04,
0x63, 0x6f, 0x64, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f,
0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f,
0x6e, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x89, 0x01, 0x0a, 0x0f, 0x53, 0x65, 0x6e, 0x64, 0x41, 0x75,
0x64, 0x69, 0x6f, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73,
0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73,
0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x75, 0x64, 0x69,
0x6f, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x61, 0x75,
0x64, 0x69, 0x6f, 0x44, 0x61, 0x74, 0x61, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x5f, 0x66,
0x6c, 0x61, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x65, 0x6e, 0x64, 0x46, 0x6c,
0x61, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74,
0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x64, 0x61, 0x74, 0x61, 0x43, 0x6f, 0x75, 0x6e,
0x74, 0x22, 0x9f, 0x02, 0x0a, 0x11, 0x53, 0x65, 0x6e, 0x64, 0x41, 0x75, 0x64, 0x69, 0x6f, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x69,
0x73, 0x5f, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08,
0x69, 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x66,
0x69, 0x6e, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x46, 0x69,
0x6e, 0x61, 0x6c, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69,
0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e,
0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x05, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x12, 0x20, 0x0a, 0x0b,
0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1b,
0x0a, 0x09, 0x6a, 0x73, 0x6f, 0x6e, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x07, 0x20, 0x01, 0x28,
0x09, 0x52, 0x08, 0x6a, 0x73, 0x6f, 0x6e, 0x44, 0x61, 0x74, 0x61, 0x12, 0x27, 0x0a, 0x0f, 0x73,
0x70, 0x65, 0x65, 0x63, 0x68, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08,
0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x73, 0x70, 0x65, 0x65, 0x63, 0x68, 0x44, 0x75, 0x72, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x69, 0x6e, 0x64,
0x65, 0x78, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x64, 0x61, 0x74, 0x61, 0x49, 0x6e,
0x64, 0x65, 0x78, 0x22, 0x30, 0x0a, 0x0f, 0x48, 0x65, 0x61, 0x72, 0x74, 0x42, 0x65, 0x61, 0x74,
0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f,
0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73,
0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x68, 0x0a, 0x11, 0x48, 0x65, 0x61, 0x72, 0x74, 0x42, 0x65,
0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f,
0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x1d,
0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x20, 0x0a,
0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22,
0x2a, 0x0a, 0x09, 0x52, 0x65, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x1d, 0x0a, 0x0a,
0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x62, 0x0a, 0x0b, 0x52,
0x65, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f,
0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x1d,
0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x20, 0x0a,
0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x32,
0xda, 0x01, 0x0a, 0x0e, 0x52, 0x61, 0x69, 0x73, 0x6f, 0x75, 0x6e, 0x64, 0x53, 0x70, 0x65, 0x65,
0x63, 0x68, 0x12, 0x2e, 0x0a, 0x10, 0x49, 0x6e, 0x69, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d,
0x69, 0x6e, 0x67, 0x41, 0x53, 0x52, 0x12, 0x0b, 0x2e, 0x49, 0x6e, 0x69, 0x74, 0x43, 0x6f, 0x6e,
0x66, 0x69, 0x67, 0x1a, 0x0d, 0x2e, 0x49, 0x6e, 0x69, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x12, 0x38, 0x0a, 0x0c, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x41,
0x53, 0x52, 0x12, 0x10, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x41, 0x75, 0x64, 0x69, 0x6f, 0x43, 0x6f,
0x6e, 0x66, 0x69, 0x67, 0x1a, 0x12, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x41, 0x75, 0x64, 0x69, 0x6f,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x12, 0x2b, 0x0a, 0x0f,
0x52, 0x65, 0x6c, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x41, 0x53, 0x52, 0x12,
0x0a, 0x2e, 0x52, 0x65, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x0c, 0x2e, 0x52, 0x65,
0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x31, 0x0a, 0x09, 0x48, 0x65, 0x61,
0x72, 0x74, 0x42, 0x65, 0x61, 0x74, 0x12, 0x10, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x42, 0x65,
0x61, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x12, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74,
0x42, 0x65, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x1e, 0x5a, 0x1c,
0x2e, 0x2f, 0x52, 0x61, 0x69, 0x73, 0x6f, 0x75, 0x6e, 0x64, 0x2d, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x3b, 0x72, 0x61, 0x69, 0x73, 0x6f, 0x75, 0x6e, 0x64, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
var (
file_Raisound_protobuf_raisound_proto_rawDescOnce sync.Once
file_Raisound_protobuf_raisound_proto_rawDescData = file_Raisound_protobuf_raisound_proto_rawDesc
)
func file_Raisound_protobuf_raisound_proto_rawDescGZIP() []byte {
file_Raisound_protobuf_raisound_proto_rawDescOnce.Do(func() {
file_Raisound_protobuf_raisound_proto_rawDescData = protoimpl.X.CompressGZIP(file_Raisound_protobuf_raisound_proto_rawDescData)
})
return file_Raisound_protobuf_raisound_proto_rawDescData
}
var file_Raisound_protobuf_raisound_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
var file_Raisound_protobuf_raisound_proto_goTypes = []interface{}{
(*InitConfig)(nil), // 0: InitConfig
(*InitResponse)(nil), // 1: InitResponse
(*SendAudioConfig)(nil), // 2: SendAudioConfig
(*SendAudioResponse)(nil), // 3: SendAudioResponse
(*HeartBeatConfig)(nil), // 4: HeartBeatConfig
(*HeartBeatResponse)(nil), // 5: HeartBeatResponse
(*RelConfig)(nil), // 6: RelConfig
(*RelResponse)(nil), // 7: RelResponse
}
var file_Raisound_protobuf_raisound_proto_depIdxs = []int32{
0, // 0: RaisoundSpeech.InitStreamingASR:input_type -> InitConfig
2, // 1: RaisoundSpeech.StreamingASR:input_type -> SendAudioConfig
6, // 2: RaisoundSpeech.RelStreamingASR:input_type -> RelConfig
4, // 3: RaisoundSpeech.HeartBeat:input_type -> HeartBeatConfig
1, // 4: RaisoundSpeech.InitStreamingASR:output_type -> InitResponse
3, // 5: RaisoundSpeech.StreamingASR:output_type -> SendAudioResponse
7, // 6: RaisoundSpeech.RelStreamingASR:output_type -> RelResponse
5, // 7: RaisoundSpeech.HeartBeat:output_type -> HeartBeatResponse
4, // [4:8] is the sub-list for method output_type
0, // [0:4] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_Raisound_protobuf_raisound_proto_init() }
func file_Raisound_protobuf_raisound_proto_init() {
if File_Raisound_protobuf_raisound_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_Raisound_protobuf_raisound_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InitConfig); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Raisound_protobuf_raisound_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InitResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Raisound_protobuf_raisound_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SendAudioConfig); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Raisound_protobuf_raisound_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SendAudioResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Raisound_protobuf_raisound_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HeartBeatConfig); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Raisound_protobuf_raisound_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HeartBeatResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Raisound_protobuf_raisound_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*RelConfig); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_Raisound_protobuf_raisound_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*RelResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_Raisound_protobuf_raisound_proto_rawDesc,
NumEnums: 0,
NumMessages: 8,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_Raisound_protobuf_raisound_proto_goTypes,
DependencyIndexes: file_Raisound_protobuf_raisound_proto_depIdxs,
MessageInfos: file_Raisound_protobuf_raisound_proto_msgTypes,
}.Build()
File_Raisound_protobuf_raisound_proto = out.File
file_Raisound_protobuf_raisound_proto_rawDesc = nil
file_Raisound_protobuf_raisound_proto_goTypes = nil
file_Raisound_protobuf_raisound_proto_depIdxs = nil
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc.ClientConnInterface
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc.SupportPackageIsVersion6
// RaisoundSpeechClient is the client API for RaisoundSpeech service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type RaisoundSpeechClient interface {
InitStreamingASR(ctx context.Context, in *InitConfig, opts ...grpc.CallOption) (*InitResponse, error)
StreamingASR(ctx context.Context, opts ...grpc.CallOption) (RaisoundSpeech_StreamingASRClient, error)
RelStreamingASR(ctx context.Context, in *RelConfig, opts ...grpc.CallOption) (*RelResponse, error)
HeartBeat(ctx context.Context, in *HeartBeatConfig, opts ...grpc.CallOption) (*HeartBeatResponse, error)
}
type raisoundSpeechClient struct {
cc grpc.ClientConnInterface
}
func NewRaisoundSpeechClient(cc grpc.ClientConnInterface) RaisoundSpeechClient {
return &raisoundSpeechClient{cc}
}
func (c *raisoundSpeechClient) InitStreamingASR(ctx context.Context, in *InitConfig, opts ...grpc.CallOption) (*InitResponse, error) {
out := new(InitResponse)
err := c.cc.Invoke(ctx, "/RaisoundSpeech/InitStreamingASR", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *raisoundSpeechClient) StreamingASR(ctx context.Context, opts ...grpc.CallOption) (RaisoundSpeech_StreamingASRClient, error) {
stream, err := c.cc.NewStream(ctx, &_RaisoundSpeech_serviceDesc.Streams[0], "/RaisoundSpeech/StreamingASR", opts...)
if err != nil {
return nil, err
}
x := &raisoundSpeechStreamingASRClient{stream}
return x, nil
}
type RaisoundSpeech_StreamingASRClient interface {
Send(*SendAudioConfig) error
Recv() (*SendAudioResponse, error)
grpc.ClientStream
}
type raisoundSpeechStreamingASRClient struct {
grpc.ClientStream
}
func (x *raisoundSpeechStreamingASRClient) Send(m *SendAudioConfig) error {
return x.ClientStream.SendMsg(m)
}
func (x *raisoundSpeechStreamingASRClient) Recv() (*SendAudioResponse, error) {
m := new(SendAudioResponse)
if err := x.ClientStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func (c *raisoundSpeechClient) RelStreamingASR(ctx context.Context, in *RelConfig, opts ...grpc.CallOption) (*RelResponse, error) {
out := new(RelResponse)
err := c.cc.Invoke(ctx, "/RaisoundSpeech/RelStreamingASR", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *raisoundSpeechClient) HeartBeat(ctx context.Context, in *HeartBeatConfig, opts ...grpc.CallOption) (*HeartBeatResponse, error) {
out := new(HeartBeatResponse)
err := c.cc.Invoke(ctx, "/RaisoundSpeech/HeartBeat", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// RaisoundSpeechServer is the server API for RaisoundSpeech service.
type RaisoundSpeechServer interface {
InitStreamingASR(context.Context, *InitConfig) (*InitResponse, error)
StreamingASR(RaisoundSpeech_StreamingASRServer) error
RelStreamingASR(context.Context, *RelConfig) (*RelResponse, error)
HeartBeat(context.Context, *HeartBeatConfig) (*HeartBeatResponse, error)
}
// UnimplementedRaisoundSpeechServer can be embedded to have forward compatible implementations.
type UnimplementedRaisoundSpeechServer struct {
}
func (*UnimplementedRaisoundSpeechServer) InitStreamingASR(context.Context, *InitConfig) (*InitResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method InitStreamingASR not implemented")
}
func (*UnimplementedRaisoundSpeechServer) StreamingASR(RaisoundSpeech_StreamingASRServer) error {
return status.Errorf(codes.Unimplemented, "method StreamingASR not implemented")
}
func (*UnimplementedRaisoundSpeechServer) RelStreamingASR(context.Context, *RelConfig) (*RelResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method RelStreamingASR not implemented")
}
func (*UnimplementedRaisoundSpeechServer) HeartBeat(context.Context, *HeartBeatConfig) (*HeartBeatResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method HeartBeat not implemented")
}
func RegisterRaisoundSpeechServer(s *grpc.Server, srv RaisoundSpeechServer) {
s.RegisterService(&_RaisoundSpeech_serviceDesc, srv)
}
func _RaisoundSpeech_InitStreamingASR_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(InitConfig)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RaisoundSpeechServer).InitStreamingASR(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/RaisoundSpeech/InitStreamingASR",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RaisoundSpeechServer).InitStreamingASR(ctx, req.(*InitConfig))
}
return interceptor(ctx, in, info, handler)
}
func _RaisoundSpeech_StreamingASR_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(RaisoundSpeechServer).StreamingASR(&raisoundSpeechStreamingASRServer{stream})
}
type RaisoundSpeech_StreamingASRServer interface {
Send(*SendAudioResponse) error
Recv() (*SendAudioConfig, error)
grpc.ServerStream
}
type raisoundSpeechStreamingASRServer struct {
grpc.ServerStream
}
func (x *raisoundSpeechStreamingASRServer) Send(m *SendAudioResponse) error {
return x.ServerStream.SendMsg(m)
}
func (x *raisoundSpeechStreamingASRServer) Recv() (*SendAudioConfig, error) {
m := new(SendAudioConfig)
if err := x.ServerStream.RecvMsg(m); err != nil {
return nil, err
}
return m, nil
}
func _RaisoundSpeech_RelStreamingASR_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RelConfig)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RaisoundSpeechServer).RelStreamingASR(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/RaisoundSpeech/RelStreamingASR",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RaisoundSpeechServer).RelStreamingASR(ctx, req.(*RelConfig))
}
return interceptor(ctx, in, info, handler)
}
func _RaisoundSpeech_HeartBeat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HeartBeatConfig)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RaisoundSpeechServer).HeartBeat(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/RaisoundSpeech/HeartBeat",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RaisoundSpeechServer).HeartBeat(ctx, req.(*HeartBeatConfig))
}
return interceptor(ctx, in, info, handler)
}
var _RaisoundSpeech_serviceDesc = grpc.ServiceDesc{
ServiceName: "RaisoundSpeech",
HandlerType: (*RaisoundSpeechServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "InitStreamingASR",
Handler: _RaisoundSpeech_InitStreamingASR_Handler,
},
{
MethodName: "RelStreamingASR",
Handler: _RaisoundSpeech_RelStreamingASR_Handler,
},
{
MethodName: "HeartBeat",
Handler: _RaisoundSpeech_HeartBeat_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "StreamingASR",
Handler: _RaisoundSpeech_StreamingASR_Handler,
ServerStreams: true,
ClientStreams: true,
},
},
Metadata: "Raisound-protobuf/raisound.proto",
}
syntax = "proto3";
//执行命令
//protoc --go_out=plugins=grpc:. ./Raisound-protobuf/*.proto
option go_package = "./Raisound-protobuf;raisound";
// 初始化语音流的设置
message InitConfig {
string token = 1;
string devid = 2;
string codec = 3;
int32 sample_rate = 4;
int32 sample_bits = 5;
int32 bitrate = 6;
string scene = 7;
string lang = 8;
int32 nbest = 9;
int32 vad_level = 10;
int32 max_speech_duration = 11;
string meeting_id = 12;
string app_name = 13;
string conn_id = 14;
bool oral_flag = 15;
bool sensitive_flag = 16;
bool punc_flag = 17;
bool num_convert_flag = 18;
string user = 19;
string passwd = 20;
int32 inter_outer_flag = 21; //0表示对内,1表示对外
}
// 初始化语音流的返回
message InitResponse {
int32 code = 1;
string session_id = 2;
string description = 3;
}
// 发送语音流数据的设置
message SendAudioConfig {
string session_id = 1;
bytes audio_data = 2;
int32 end_flag = 3;
int32 data_count = 4;
}
// 发送语音流的返回
message SendAudioResponse {
int32 code = 1;
bool is_result = 2;
bool is_final = 3;
string session_id = 4;
string results = 5;
string description = 6;
string json_data = 7;
int32 speech_duration = 8;
int32 data_index = 9;
}
// 发送心跳的设置
message HeartBeatConfig {
string session_id = 1;
}
// 发送心跳的返回
message HeartBeatResponse {
int32 code = 1;
string session_id = 2;
string description = 3;
}
// 释放语音流的设置
message RelConfig {
string session_id = 1;
}
// 释放语音流的返回
message RelResponse {
int32 code = 1;
string session_id = 2;
string description = 3;
}
service RaisoundSpeech {
rpc InitStreamingASR(InitConfig) returns(InitResponse);
rpc StreamingASR(stream SendAudioConfig) returns(stream SendAudioResponse);
rpc RelStreamingASR(RelConfig) returns(RelResponse);
rpc HeartBeat(HeartBeatConfig) returns(HeartBeatResponse);
}
### 实体定义SQL
# 实体主体结构
CREATE TABLE `entity`
(
`id` INT(16) PRIMARY KEY AUTO_INCREMENT COMMENT '自增长ID',
`entity_id` VARCHAR(64) UNIQUE NOT NULL COMMENT '实体ID',
`entity_name` VARCHAR(128) UNIQUE NOT NULL COMMENT '实体ID',
`entity_number` int(8) NOT NULL COMMENT '实体条目数量',
`platform` VARCHAR(32) NOT NULL DEFAULT 'voice' COMMENT '使用平台',
`created_at` TIMESTAMP DEFAULT now() COMMENT '创建时间',
`updated_at` TIMESTAMP DEFAULT now() COMMENT '创建时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
# 实体条目内容,和实体主体结构是一对多的关联关心,关联字段是`entity_id`
CREATE TABLE `entity_items`
(
`id` INT(16) PRIMARY KEY AUTO_INCREMENT COMMENT '自增长ID',
`entity_id` VARCHAR(64) NOT NULL COMMENT '实体ID,和`entity`的`entity_id`关联',
`entity_item_index` int(8) NOT NULL COMMENT '实体内容条目的索引',
`entity_item` VARCHAR(128) NOT NULL COMMENT '实体内容条目',
`created_at` TIMESTAMP DEFAULT now() COMMENT '创建时间',
`updated_at` TIMESTAMP DEFAULT now() COMMENT '创建时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
# 查询SQL(参考)
SELECT `t1`.`entity_id`, `t1`.`entity_name`, `t1`.`entity_number`, `t2`.`entity_item_index`, `t2`.`entity_item`
FROM `entity` AS `t1`
JOIN `entity_items` AS `t2` ON `t1`.`entity_id` = `t2`.`entity_id`;
### 命令模板结构
# 命令模板结构
CREATE TABLE `command_structure`
(
`id` INT(16) PRIMARY KEY AUTO_INCREMENT COMMENT '自增长ID',
`command_intent_id` VARCHAR(64) UNIQUE NOT NULL COMMENT '命令意图模板ID',
`command_intent_name` VARCHAR(128) UNIQUE NOT NULL COMMENT '命令意图模板名称',
`command_entity_number` int(2) NOT NULL COMMENT '命令实体项中条目数',
`platform` VARCHAR(32) NOT NULL DEFAULT 'voice' COMMENT '使用平台',
`created_at` TIMESTAMP DEFAULT now() COMMENT '创建时间',
`updated_at` TIMESTAMP DEFAULT now() COMMENT '创建时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
# 命令实体项结构
CREATE TABLE `command_entity`
(
`id` INT(16) PRIMARY KEY AUTO_INCREMENT COMMENT '自增长ID',
`command_intent_id` VARCHAR(64) NOT NULL COMMENT '命令意图模板ID,和`command_structure`的`command_intent_id`关联',
`command_entity_tag` VARCHAR(128) NOT NULL COMMENT '命令实体项条目的标识',
`entity_id` VARCHAR(64) NOT NULL COMMENT '实体ID,和`entity`的`entity_id`关联',
`created_at` TIMESTAMP DEFAULT now() COMMENT '创建时间',
`updated_at` TIMESTAMP DEFAULT now() COMMENT '创建时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
# 命令样板项结构
CREATE TABLE `command_template`
(
`id` INT(16) PRIMARY KEY AUTO_INCREMENT COMMENT '自增长ID',
`command_intent_id` VARCHAR(64) NOT NULL COMMENT '命令意图模板ID,和`command_structure`的`command_intent_id`关联',
`command_template_index` int(2) NOT NULL COMMENT '命令样板项索引',
`command_template_item` VARCHAR(512) NOT NULL COMMENT '命令样板项内容',
`created_at` TIMESTAMP DEFAULT now() COMMENT '创建时间',
`updated_at` TIMESTAMP DEFAULT now() COMMENT '创建时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
SELECT command_intent_id,command_intent_name FROM command_structure;
SELECT * FROM command_entity WHERE command_intent_id='24508051244799537092493312';
SELECT * FROM command_template WHERE command_intent_id='24508051244799537092493312';
SELECT * FROM entity_items WHERE entity_id='1111111111';
USE bot_know_db;
SELECT t1.command_intent_name, t3.command_entity_tag, t4.entity_name, t5.entity_item, t2.command_template_item
FROM command_structure AS t1
JOIN command_template AS t2 ON t1.command_intent_id = t2.command_intent_id
JOIN command_entity AS t3 ON t1.command_intent_id = t3.command_intent_id
JOIN entity AS t4 ON t3.entity_id = t4.entity_id
JOIN entity_items AS t5 ON t5.entity_id = t4.entity_id WHERE t1.command_intent_id='24508051244799537092493312';
# # 命令模板样板项SQL查询(参考)
# SELECT `t1`.`command_intent_id`,
# `t1`.`command_intent_name`,
# `t1`.`command_template_id`,
# `t2`.`command_template_index`,
# `t2`.`command_template_item`
# FROM `command_structure` AS `t1`
# JOIN `command_template` AS `t2` ON `t1`.`command_template_id` = `t2`.`command_template_id`;
#
#
# ### 训练模板需要的数据查询SQL(参考)
# SELECT `t1`.command_intent_name,
# `t1`.command_entity_id,
# `t2`.command_entity_tag,
# `t2`.entity_id,
# `t4`.entity_name,
# `t5`.entity_item,
# `t3`.command_template_index,
# `t3`.command_template_item
# FROM command_structure AS `t1`
# JOIN command_entity AS `t2` ON `t1`.command_entity_id = `t2`.command_entity_id
# JOIN command_template AS `t3` ON `t1`.command_template_id = `t3`.command_template_id
# JOIN entity AS `t4` ON `t2`.entity_id = `t4`.entity_id
# JOIN entity_items AS `t5` ON `t4`.entity_id = `t5`.entity_id;
\ No newline at end of file
[common]
port = 20065 #端口
defaultLanguage = ZH-CN #默认语种,目前只有三个值ZH-CN(普通话)、ZH-HK(粤语)、EN(英语)
checkTokenURL = http:// #校验token以认证连接
redisURL = huisheng_redis:6379 #redis连接地址,格式为【ip:port】
redisChannel = send audio info #redis的public的通道
hotWordURL = http://192.168.0.61/huisheng_api_gm/hotwords/new/personal/model/get #通过user_id获取热词文本的地址
[mysql]
mysqlUse = false # false为禁用,即禁用日志数据保存在mysql。true即否则则否
mysqlIp = 172.16.5.29
mysqlPort = 3320
mysqlUser = root
mysqlPasswd = imslimsl # 禁止带有有`#`
mysqlDatabase = bot_know_db
[ZH-CN]
websocketArr = ws://huisheng_offline:20086 # 英气地址,可多个,多个是用英文逗号”,“隔开
defaultHotWordFile = #默认热词完整地址名称
digitConvertURL = http://huisheng_itn:8305/encode #转数字
sensitiveWordURL = http://huisheng_itn:8306/encode #敏感词
punctuationURL = http://huisheng_itn:8125/encode #标点符号处理
postURL = http://
[ZH-HK]
websocketArr = ws://huisheng_offline_cantonese:20086/ # 英气地址,可多个,多个是用英文逗号”,“隔开
defaultHotWordFile = /opt/huisheng/data/hotword/a.txt #默认热词完整地址名称
digitConvertURL = http://huisheng_itn:8305/encode #转数字
sensitiveWordURL = http://huisheng_itn:8306/encode #敏感词
punctuationURL = http://huisheng_itn:8125/encode #标点符号处理
postURL = http://
[EN]
websocketArr = ws://huisheng_offline_english:20086/ # 英气地址,可多个,多个是用英文逗号”,“隔开
defaultHotWordFile = /opt/huisheng/data/hotword/a.txt #默认热词完整地址名称
e2nURL = http://huisheng_itn_english:8120/e2n
punctuationURL = http://huisheng_itn_english:8126/encode
[fileConf]
logName = /opt/huisheng/data/log/grpc-golang-base/log/server.log #日志地址
audioPath = /opt/huisheng/data/wav/grpc-golang-base/audio #音频地址
\ No newline at end of file
package engineServer
import (
"encoding/json"
"errors"
"fmt"
"gRPC-Raisound-Base-second-pass/initServer"
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"log"
"sync"
"time"
)
type Engine struct {
Conn *websocket.Conn
lang string
contextPath string
ipStr string
ConnectNum int
isCloseRead bool
isCloseWrite bool
IsEnd bool
isClose bool
preEndTime float64
preSpeechTime float64
preResult map[string]interface{}
resultChan chan []byte
isSwitch bool
isRestart bool
isRestartLock sync.RWMutex
}
func InitEngine(lang, contextPath string) (engine *Engine, err error) {
var (
conn *websocket.Conn
)
engine = &Engine{
Conn: conn,
lang: lang,
contextPath: contextPath,
preResult: make(map[string]interface{}),
resultChan: make(chan []byte, 1024),
}
if conn, err = engine.determineWsConn(lang, contextPath); err != nil {
return
} else {
if conn != nil {
engine.Conn = conn
if lang == "ZH-CN" {
initServer.ZhCnLock.Lock()
initServer.ZhCn[engine.ipStr]["num"] = initServer.ZhCn[engine.ipStr]["num"].(int) + 1
//log.Println(initServer.ZhCn)
initServer.ZhCnLock.Unlock()
}
if lang == "ZH_HK" {
initServer.ZhHkLock.Lock()
initServer.ZhHk[engine.ipStr]["num"] = initServer.ZhHk[engine.ipStr]["num"].(int) + 1
//log.Println(initServer.ZhHk)
initServer.ZhHkLock.Unlock()
}
if lang == "EN" {
initServer.ENLock.Lock()
initServer.EN[engine.ipStr]["num"] = initServer.EN[engine.ipStr]["num"].(int) + 1
//log.Println(initServer.EN)
initServer.ENLock.Unlock()
}
} else {
err = errors.New("connected engine failed")
return
}
}
go engine.readMsgLoop()
return
}
func (Conn *Engine) determineWsConn(lang, contextPath string) (conn *websocket.Conn, err error) {
//log.Println("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT")
var (
ipStr string
ConNum int
isFirst bool
//recData []byte
//recParams = make(map[string]interface{})
)
if lang == "ZH-CN" {
initServer.ZhCnLock.Lock()
logrus.Println(initServer.ZhCn)
for ip, info := range initServer.ZhCn {
if info["alive"].(bool) {
if !isFirst {
ipStr = ip
ConNum = info["num"].(int)
isFirst = true
continue
}
if ConNum >= info["num"].(int) {
ipStr = ip
ConNum = info["num"].(int)
}
}
}
initServer.ZhCnLock.Unlock()
}
if lang == "ZH-HK" {
initServer.ZhHkLock.Lock()
logrus.Println(initServer.ZhHk)
for ip, info := range initServer.ZhHk {
if info["alive"].(bool) {
if !isFirst {
ipStr = ip
ConNum = info["num"].(int)
isFirst = true
continue
}
if ConNum >= info["num"].(int) {
ipStr = ip
ConNum = info["num"].(int)
}
}
}
initServer.ZhHkLock.Unlock()
}
if lang == "EN" {
initServer.ENLock.Lock()
logrus.Println(initServer.EN)
for ip, info := range initServer.EN {
if info["alive"].(bool) {
if !isFirst {
ipStr = ip
ConNum = info["num"].(int)
isFirst = true
continue
}
if ConNum >= info["num"].(int) {
ipStr = ip
ConNum = info["num"].(int)
}
}
}
initServer.ENLock.Unlock()
}
logrus.Println("connection address:", ipStr)
if ipStr != "" {
if conn, _, err = websocket.DefaultDialer.Dial(ipStr, nil); err != nil {
if Conn.ConnectNum > 10 {
err = errors.New("connected engine failed")
Conn.ConnectNum = 0
return
}
Conn.ConnectNum++
time.Sleep(1 * time.Second)
return Conn.determineWsConn(lang, contextPath)
}
if conn == nil {
if Conn.ConnectNum > 10 {
err = errors.New("connected engine failed")
Conn.ConnectNum = 0
return
}
Conn.ConnectNum++
time.Sleep(1 * time.Second)
return Conn.determineWsConn(lang, contextPath)
} else {
//contextPath = ""
if contextPath != "" {
loadText := fmt.Sprintf(`{"signal": "start", "continuous_decoding": %v, "nbest": 10, "enable_vad": %v, "chunk_size": 12, "two_pass": %v, "context_update":%v,"context_score": 5.0, "context_path": "%v"}`, true, true, true, true, contextPath)
logrus.Println(loadText)
//err = conn.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf(`{ "signal": "reload_context", "context_score": 5.0, "context_path": "%v", "update": %v}`, contextPath, true)))
//_ = conn.SetReadDeadline(time.Now().Add(300 * time.Millisecond))
if err = conn.WriteMessage(websocket.TextMessage, []byte(loadText)); err != nil {
logrus.Errorln(err.Error())
time.Sleep(1 * time.Second)
return Conn.determineWsConn(lang, contextPath)
}
//if _, recData, err = conn.ReadMessage(); err != nil {
// logrus.Println(err)
// _ = conn.Close()
// if conn, _, err = websocket.DefaultDialer.Dial(ipStr, nil); err != nil {
// if Conn.ConnectNum > 10 {
// err = errors.New("connected engine failed")
// Conn.ConnectNum = 0
// return
// }
// time.Sleep(1 * time.Second)
// Conn.ConnectNum++
// return Conn.determineWsConn(lang, contextPath)
// }
// if conn != nil {
// _ = conn.WriteMessage(websocket.TextMessage, []byte(`{"signal" : "start","nbest" :1,"continuous_decoding": true}`))
// }
//} else {
// logrus.Println(string(recData))
// if err = json.Unmarshal(recData, &recParams); err != nil {
// _ = conn.WriteMessage(websocket.TextMessage, []byte(`{"signal" : "start","nbest" :1,"continuous_decoding": true}`))
// } else {
// if _, ok := recParams["status"]; ok {
// if recParams["status"].(string) == "ok" && recParams["type"].(string) == "reload_end" {
// if err = conn.WriteMessage(websocket.TextMessage, []byte(`{"signal" : "start","nbest" :1,"continuous_decoding": true}`)); err != nil {
// }
// } else {
// _ = conn.Close()
// if conn, _, err = websocket.DefaultDialer.Dial(ipStr, nil); err != nil {
// logrus.Println(err.Error())
// }
// if conn != nil {
// if err = conn.WriteMessage(websocket.TextMessage, []byte(`{"signal" : "start","nbest" :1,"continuous_decoding": true}`)); err != nil {
// }
// }
// }
// } else {
// if conn, _, err = websocket.DefaultDialer.Dial(ipStr, nil); err != nil {
// logrus.Println(err)
// }
// if conn != nil {
// _ = conn.WriteMessage(websocket.TextMessage, []byte(`{"signal" : "start","nbest" :1,"continuous_decoding": true}`))
// }
// }
// }
//}
} else {
logrus.Println(fmt.Sprintf(`{"signal": "start", "continuous_decoding": %v, "nbest": 10, "enable_vad": %v, "chunk_size": 12, "two_pass": %v, "context_update":%v}`, true, true, true, true))
if conn != nil {
err = conn.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf(`{"signal": "start", "continuous_decoding": %v, "nbest": 10, "enable_vad": %v, "chunk_size": 12, "two_pass": %v}`, true, true, true)))
if err != nil {
logrus.Errorln(err.Error())
time.Sleep(1 * time.Second)
return Conn.determineWsConn(lang, contextPath)
}
}
}
if conn == nil {
if Conn.ConnectNum > 10 {
err = errors.New("connected engine failed")
Conn.ConnectNum = 0
return
}
Conn.ConnectNum++
time.Sleep(1 * time.Second)
return Conn.determineWsConn(lang, contextPath)
}
}
Conn.ipStr = ipStr
Conn.ConnectNum = 0
} else {
logrus.Println("1111111111111111111111111111", ipStr)
if Conn.ConnectNum > 10 {
err = errors.New("all engine is dead")
Conn.ConnectNum = 0
return
}
Conn.ConnectNum++
time.Sleep(1 * time.Second)
return Conn.determineWsConn(lang, contextPath)
}
return
}
func (Conn *Engine) write(data []byte) (err error) {
select {
case Conn.resultChan <- data:
//case <-time.After(1 * time.Second):
// err = errors.New("not message")
}
return
}
func (Conn *Engine) ReadMsg() (recData map[string]interface{}, err error) {
var data []byte
recData = make(map[string]interface{})
select {
case data = <-Conn.resultChan:
if err = json.Unmarshal(data, &recData); err != nil {
return
}
//case <-time.After(5 * time.Second):
// err = errors.New("not message")
}
return
}
func (Conn *Engine) readMsgLoop() {
var (
data = make(map[string]interface{})
recData []byte
err error
)
for {
//logrus.Println("11111111111111111")
if data, err = Conn.readMsg(); err != nil {
logrus.Errorln("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", err)
goto ERR
}
//if _, ok := data["results"]; ok {
// if _, ok = data["end"]; ok {
// switch data["end"].(type) {
// case float64:
// if data["results"].(string) == "" && data["end"].(float64) == 0 {
// continue
// }
// case int:
// if data["results"].(string) == "" && data["end"].(int) == 0 {
// continue
// }
// }
// } else {
// continue
// }
//} else {
// continue
//}
if recData, err = json.Marshal(data); err != nil {
goto ERR
}
if err = Conn.write(recData); err != nil {
goto ERR
}
}
ERR:
close(Conn.resultChan)
}
func (Conn *Engine) readMsg() (recData map[string]interface{}, err error) {
var (
data []byte
dataParams = make(map[string]interface{})
)
recData = make(map[string]interface{})
if !Conn.isCloseRead {
if Conn.Conn != nil {
if _, data, err = Conn.Conn.ReadMessage(); err != nil {
logrus.Errorln(err)
if !Conn.isCloseWrite {
Conn.isRestartLock.Lock()
if !Conn.isRestart {
Conn.isRestart = true
if Conn.Conn != nil {
_ = Conn.Conn.Close()
}
if Conn.Conn, err = Conn.determineWsConn(Conn.lang, Conn.contextPath); err != nil {
logrus.Errorln(err)
return
}
}
Conn.isRestart = false
Conn.isRestartLock.Unlock()
return Conn.readMsg()
} else {
_ = Conn.write([]byte(`{"is_final":3,"desc":"speech_end"}`))
err = errors.New("the speech end")
}
if Conn.preResult != nil {
if _, ok := Conn.preResult["is_final"]; ok {
if Conn.preResult["is_final"].(int) == 1 {
return Conn.readMsg()
} else {
Conn.preResult["is_final"] = 1
}
recData = Conn.preResult
logrus.Println(recData)
}
}
return
}
log.Println(string(data))
if len(data) < 10 {
recData["results"] = ""
recData["is_final"] = 0
recData["start"] = 0
recData["end"] = 0
recData["duration"] = 0
return Conn.readMsg()
}
//logrus.Println(string(data))
if err = json.Unmarshal(data, &dataParams); err != nil {
recData = Conn.preResult
err = nil
return
}
if _, okStatus := dataParams["status"]; okStatus {
if dataType, okType := dataParams["type"]; okType {
if dataType.(string) == "wait" || dataType.(string) == "server_ready" || dataType.(string) == "reload_end" {
recData["results"] = ""
recData["is_final"] = 0
recData["start"] = 0
recData["end"] = 0
recData["duration"] = 0
}
if dataType.(string) == "partial_result" {
recData["is_final"] = 0
bestFormat := dataParams["nbest"].([]interface{})
if len(bestFormat) > 0 {
recData["results"] = bestFormat[0].(map[string]interface{})["sentence"].(string)
} else {
recData["results"] = ""
}
recData["start"] = dataParams["timestamp"].(map[string]interface{})["start"].(float64)
recData["end"] = dataParams["timestamp"].(map[string]interface{})["end"].(float64)
recData["duration"] = int(recData["end"].(float64)-recData["start"].(float64)) * 32
Conn.preResult = recData
}
if dataType.(string) == "final_result" {
recData["start"] = dataParams["timestamp"].(map[string]interface{})["start"].(float64)
recData["end"] = dataParams["timestamp"].(map[string]interface{})["end"].(float64)
if recData["start"].(float64) == 0 {
Conn.preSpeechTime = Conn.preEndTime
}
Conn.preEndTime = recData["end"].(float64) + Conn.preSpeechTime
recData["is_final"] = 0
recData["results"] = ""
recData["start"] = 0
recData["end"] = 0
recData["duration"] = 0
return Conn.readMsg()
//bestFormat := dataParams["nbest"].([]interface{})
//if len(bestFormat) > 0 {
// recData["results"] = bestFormat[0].(map[string]interface{})["sentence"].(string)
//} else {
// recData["results"] = ""
//}
//recData["start"] = dataParams["timestamp"].(map[string]interface{})["start"].(float64) + Conn.preSpeechTime
//recData["end"] = dataParams["timestamp"].(map[string]interface{})["end"].(float64) + Conn.preSpeechTime
//if recData["start"].(float64) == 0 {
// Conn.preSpeechTime = Conn.preEndTime
//
//}
//Conn.preEndTime = recData["end"].(float64)
////if Conn.preEndTime != recData["start"].(float64) {
//// recData["start"] = Conn.preEndTime
////}
////if recData["end"].(float64) < Conn.preEndTime {
//// recData["end"] = recData["end"].(float64) + Conn.preSpeechTime
//// Conn.preEndTime = recData["end"].(float64)
////} else {
//// Conn.preEndTime = recData["end"].(float64)
////}
//recData["duration"] = int(recData["end"].(float64)-recData["start"].(float64)) * 32
//if recData["results"] != "" {
// log.Println(recData)
// recData["results"] = "!!!!!!!!!!!!!"
//}
////recData["results"] = ""
//Conn.preResult = recData
////log.Println(recData)
}
if dataType.(string) == "final_result_second_pass" {
recData["is_final"] = 1
bestFormat := dataParams["nbest"].([]interface{})
if len(bestFormat) > 0 {
recData["results"] = bestFormat[0].(map[string]interface{})["sentence"].(string)
} else {
recData["results"] = ""
}
recData["start"] = dataParams["timestamp"].(map[string]interface{})["start"].(float64) + Conn.preSpeechTime
recData["end"] = dataParams["timestamp"].(map[string]interface{})["end"].(float64) + Conn.preSpeechTime
//Conn.preEndTime = recData["end"].(float64)
log.Println("second_pass", recData)
//if recData["results"].(string) == "" {
// recData["results"] = "@@@@"
//}
//
//if recData["start"].(float64) == 0 {
// Conn.preSpeechTime = Conn.preEndTime
//}
//if Conn.preEndTime != recData["start"].(float64) {
// recData["start"] = Conn.preEndTime
// //if recData["end"].(float64) != 0 {
// // recData["start"] = Conn.preEndTime
// //}
//}
//if recData["end"].(float64) < Conn.preEndTime {
// recData["end"] = recData["end"].(float64) + Conn.preSpeechTime
// Conn.preEndTime = recData["end"].(float64)
// //if recData["end"].(float64) != 0 {
// // recData["end"] = recData["end"].(float64) + Conn.preEndTime
// // Conn.preEndTime = recData["end"].(float64)
// //}
//} else {
// Conn.preEndTime = recData["end"].(float64)
//}
recData["duration"] = int(recData["end"].(float64)-recData["start"].(float64)) * 32
Conn.preResult = recData
}
if dataType.(string) == "speech_end" {
time.Sleep(200 * time.Millisecond)
if !Conn.isCloseWrite {
_ = Conn.Conn.Close()
logrus.Println("the engine end speech,try to connect it:", Conn.lang, Conn.contextPath)
Conn.Conn, _ = Conn.determineWsConn(Conn.lang, Conn.contextPath)
Conn.isSwitch = false
} else {
Conn.IsEnd = true
_ = Conn.write([]byte(fmt.Sprintf(`{"is_final":%v,"desc":"speech_end"}`, float64(3))))
err = errors.New("the speech end")
}
//Conn.IsEnd = true
}
} else {
err = errors.New("data format error:" + string(data))
}
} else {
if Conn.preResult["is_final"].(int) != 1 {
Conn.preResult["is_final"] = 1
}
recData = Conn.preResult
err = errors.New("connection is closed")
return
}
} else {
if Conn.Conn, err = Conn.determineWsConn(Conn.lang, Conn.contextPath); err != nil {
return
}
return Conn.readMsg()
}
} else {
err = errors.New("read engine message closed")
}
return
}
func (Conn *Engine) WriteMsg(writeData []byte, datatype int) (err error) {
if Conn.isRestart {
Conn.isRestartLock.Lock()
Conn.isRestartLock.Unlock()
}
if !Conn.isCloseWrite {
if Conn.Conn != nil {
if Conn.isSwitch {
time.Sleep(100 * time.Millisecond)
return Conn.WriteMsg(writeData, datatype)
}
if datatype == 0 {
//logrus.Println("=============>>>>>> the audio length:", len(writeData))
if err = Conn.Conn.WriteMessage(websocket.BinaryMessage, writeData); err != nil {
logrus.Errorln(err)
if Conn.Conn, err = Conn.determineWsConn(Conn.lang, Conn.contextPath); err != nil {
return
}
return Conn.WriteMsg(writeData, datatype)
}
}
if datatype == 1 {
Conn.isCloseWrite = true
if err = Conn.Conn.WriteMessage(websocket.TextMessage, writeData); err != nil {
logrus.Error(err)
return
}
}
if datatype == 2 {
//logrus.Println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS", `{"signal" : "end"}`)
if err = Conn.Conn.WriteMessage(websocket.TextMessage, []byte(`{"signal" : "end"}`)); err != nil {
logrus.Error(err)
return
}
}
if datatype == 3 {
//logrus.Println("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE", string(writeData))
jsonMap := make(map[string]interface{})
if err = json.Unmarshal(writeData, &jsonMap); err != nil {
logrus.Error(err)
return
}
if jsonMap["language"].(string) == "ZH-CN" || jsonMap["language"].(string) == "ZH-HK" || jsonMap["language"].(string) == "EN" {
Conn.lang = jsonMap["language"].(string)
if Conn.lang == "ZH-CN" {
Conn.contextPath = initServer.ConfigMap["hotWord-ZH-CN"].(string)
}
if Conn.lang == "ZH-HK" {
Conn.contextPath = initServer.ConfigMap["hotWord-ZH-HK"].(string)
}
if Conn.lang == "EN" {
Conn.contextPath = initServer.ConfigMap["hotWord-EN"].(string)
}
}
if err = Conn.Conn.WriteMessage(websocket.TextMessage, []byte(`{"signal" : "end"}`)); err != nil {
logrus.Error(err)
return
}
Conn.isSwitch = true
logrus.Println(`{"signal" : "end"}`)
}
} else {
if Conn.Conn, err = Conn.determineWsConn(Conn.lang, Conn.contextPath); err != nil {
return
}
return Conn.WriteMsg(writeData, datatype)
}
} else {
err = errors.New("write engine message closed")
}
return
}
func (Conn *Engine) CloseEngine() (err error) {
if Conn != nil {
Conn.isCloseWrite = true
//if Conn.Conn != nil{
// _ = Conn.Conn.WriteMessage(websocket.TextMessage,[]byte(`{"signal" : "end"}`))
//}
time.Sleep(200 * time.Millisecond)
Conn.isCloseRead = true
if Conn.Conn != nil {
if Conn.IsEnd {
_ = Conn.Conn.Close()
Conn.IsEnd = false
}
_ = Conn.Conn.Close()
}
if !Conn.isClose {
Conn.isClose = true
if Conn.lang == "ZH-CN" {
initServer.ZhCnLock.Lock()
if _, ok := initServer.ZhCn[Conn.ipStr]["num"]; ok {
if initServer.ZhCn[Conn.ipStr]["num"].(int) > 0 {
initServer.ZhCn[Conn.ipStr]["num"] = initServer.ZhCn[Conn.ipStr]["num"].(int) - 1
//logrus.Println(initServer.ZhCn)
}
}
initServer.ZhCnLock.Unlock()
}
if Conn.lang == "ZH-HK" {
initServer.ZhHkLock.Lock()
if _, ok := initServer.ZhHk[Conn.ipStr]["num"]; ok {
if initServer.ZhHk[Conn.ipStr]["num"].(int) > 0 {
initServer.ZhHk[Conn.ipStr]["num"] = initServer.ZhHk[Conn.ipStr]["num"].(int) - 1
//logrus.Println(initServer.ZhHk)
}
}
initServer.ZhHkLock.Unlock()
}
if Conn.lang == "EN" {
initServer.ENLock.Lock()
if _, ok := initServer.EN[Conn.ipStr]["num"]; ok {
if initServer.EN[Conn.ipStr]["num"].(int) > 0 {
initServer.EN[Conn.ipStr]["num"] = initServer.EN[Conn.ipStr]["num"].(int) - 1
//logrus.Println(initServer.EN)
}
}
initServer.ENLock.Unlock()
}
}
}
return
}
package initServer
import (
"flag"
"gRPC-Raisound-Base-second-pass/otherHandler"
"github.com/go-ini/ini"
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
"log"
"os"
"strings"
"sync"
"time"
)
// 配置文件数据结构
var (
Version bool
Config = flag.String("config", "./config.ini", "the server config")
ConfigMap = make(map[string]interface{})
ZhCn = make(map[string]map[string]interface{})
ZhCnLock sync.Mutex
ZhHk = make(map[string]map[string]interface{})
ZhHkLock sync.Mutex
EN = make(map[string]map[string]interface{})
ENLock sync.Mutex
Log *Logger
LogData *otherHandler.LogDataHandler
Snow *otherHandler.SnowflakeBase
)
// TODO: 配置文件处理
func GetConfig() {
var (
conf *ini.File
err error
)
if conf, err = ini.Load(*Config); err != nil {
panic(err.Error())
}
if conf != nil {
//common
ConfigMap["port"] = conf.Section("common").Key("port").String()
ConfigMap["checkTokenURL"] = conf.Section("common").Key("checkTokenURL").String()
ConfigMap["defaultLanguage"] = conf.Section("common").Key("defaultLanguage").String()
ConfigMap["redisURL"] = conf.Section("common").Key("redisURL").String()
ConfigMap["redisChannel"] = conf.Section("common").Key("redisChannel").String()
ConfigMap["hotWordURL"] = conf.Section("common").Key("hotWordURL").String()
if ConfigMap["defaultLanguage"].(string) == "" {
ConfigMap["defaultLanguage"] = "ZH-CN"
}
// mysql
if isMysqlUse, e := conf.Section("mysql").Key("mysqlUse").Bool(); e != nil {
logrus.Fatalln(e)
} else {
ConfigMap["mysqlUse"] = isMysqlUse
}
ConfigMap["mysqlIp"] = conf.Section("mysql").Key("mysqlIp").String()
ConfigMap["mysqlPort"] = conf.Section("mysql").Key("mysqlPort").String()
ConfigMap["mysqlUser"] = conf.Section("mysql").Key("mysqlUser").String()
ConfigMap["mysqlPasswd"] = conf.Section("mysql").Key("mysqlPasswd").String()
ConfigMap["mysqlDatabase"] = conf.Section("mysql").Key("mysqlDatabase").String()
// ZH-CN
ConfigMap["websocketArrZH-CN"] = strings.Split(conf.Section("ZH-CN").Key("websocketArr").String(), ",")
ConfigMap["hotWord-ZH-CN"] = conf.Section("ZH-CN").Key("defaultHotWordFile").String()
ConfigMap["digitConvertURL-ZH-CN"] = conf.Section("ZH-CN").Key("digitConvertURL").String()
ConfigMap["sensitiveWordURL-ZH-CN"] = conf.Section("ZH-CN").Key("sensitiveWordURL").String()
ConfigMap["punctuationURL-ZH-CN"] = conf.Section("ZH-CN").Key("punctuationURL").String()
ConfigMap["postURL-ZH-CN"] = conf.Section("ZH-CN").Key("postURL").String()
// ZH-HK
ConfigMap["websocketArrZH-HK"] = strings.Split(conf.Section("ZH-HK").Key("websocketArr").String(), ",")
ConfigMap["hotWord-ZH-HK"] = conf.Section("ZH-HK").Key("defaultHotWordFile").String()
ConfigMap["digitConvertURL-ZH-HK"] = conf.Section("ZH-HK").Key("digitConvertURL").String()
ConfigMap["sensitiveWordURL-ZH-HK"] = conf.Section("ZH-HK").Key("sensitiveWordURL").String()
ConfigMap["punctuationURL-ZH-HK"] = conf.Section("ZH-HK").Key("punctuationURL").String()
ConfigMap["postURL-ZH-HK"] = conf.Section("ZH-HK").Key("postURL").String()
// EN
ConfigMap["websocketArrEN"] = strings.Split(conf.Section("EN").Key("websocketArr").String(), ",")
ConfigMap["hotWord-EN"] = conf.Section("EN").Key("defaultHotWordFile").String()
ConfigMap["e2nURL"] = conf.Section("EN").Key("e2nURL").String()
ConfigMap["EnPunctuationURL"] = conf.Section("EN").Key("punctuationURL").String()
// fileConf
ConfigMap["logName"] = conf.Section("fileConf").Key("logName").String()
ConfigMap["audioPath"] = conf.Section("fileConf").Key("audioPath").String()
} else {
panic("config error")
}
go func() {
// 创建文件夹
_, e := os.Stat(ConfigMap["audioPath"].(string))
if os.IsNotExist(e) {
if e = os.MkdirAll(ConfigMap["audioPath"].(string), os.ModePerm); e != nil {
log.Println(e.Error())
}
}
}()
// 中文迎请探针
go func(arr []string) {
for _, ip := range arr {
value := make(map[string]interface{})
value["num"] = 0
value["alive"] = true
ZhCn[ip] = value
}
for {
var group sync.WaitGroup
ZhCnLock.Lock()
for _, ip := range arr {
group.Add(1)
go func(ipStr string) {
if c, _, e := websocket.DefaultDialer.Dial(ipStr, nil); e != nil {
ZhCn[ipStr]["alive"] = false
} else {
if c != nil {
_ = c.Close()
ZhCn[ipStr]["alive"] = true
} else {
ZhCn[ipStr]["alive"] = false
}
}
group.Done()
}(ip)
}
group.Wait()
ZhCnLock.Unlock()
time.Sleep(10 * time.Second)
}
}(ConfigMap["websocketArrZH-CN"].([]string))
// 粤语迎请探针
go func(arr []string) {
for _, ip := range arr {
value := make(map[string]interface{})
value["num"] = 0
value["alive"] = true
ZhHk[ip] = value
}
for {
var group sync.WaitGroup
ZhHkLock.Lock()
for _, ip := range arr {
group.Add(1)
go func(ipStr string) {
if c, _, e := websocket.DefaultDialer.Dial(ipStr, nil); e != nil {
ZhHk[ipStr]["alive"] = false
} else {
if c != nil {
_ = c.Close()
ZhHk[ipStr]["alive"] = true
} else {
ZhHk[ipStr]["alive"] = false
}
}
group.Done()
}(ip)
}
group.Wait()
ZhHkLock.Unlock()
time.Sleep(10 * time.Second)
}
}(ConfigMap["websocketArrZH-HK"].([]string))
// 英语迎请探针
go func(arr []string) {
for _, ip := range arr {
value := make(map[string]interface{})
value["num"] = 0
value["alive"] = true
EN[ip] = value
}
for {
var group sync.WaitGroup
ENLock.Lock()
for _, ip := range arr {
group.Add(1)
go func(ipStr string) {
if c, _, e := websocket.DefaultDialer.Dial(ipStr, nil); e != nil {
EN[ipStr]["alive"] = false
} else {
if c != nil {
_ = c.Close()
EN[ipStr]["alive"] = true
} else {
EN[ipStr]["alive"] = false
}
}
group.Done()
}(ip)
}
group.Wait()
ENLock.Unlock()
time.Sleep(10 * time.Second)
}
}(ConfigMap["websocketArrEN"].([]string))
}
func init() {
flag.BoolVar(&Version, "version", false, "")
flag.Parse()
if !Version {
logrus.SetReportCaller(true)
GetConfig()
Log, _ = InitLogger(ConfigMap["logName"].(string), "info")
if ConfigMap["mysqlUse"].(bool) {
LogData = otherHandler.InitLog(ConfigMap["mysqlIp"].(string), ConfigMap["mysqlPort"].(string), ConfigMap["mysqlUser"].(string), ConfigMap["mysqlPasswd"].(string), ConfigMap["mysqlDatabase"].(string), 1024)
Snow = otherHandler.NewSnowFlake(1)
}
}
}
package initServer
import (
"fmt"
"github.com/sirupsen/logrus"
"os"
"path"
)
type Logger struct {
Log *logrus.Logger
}
func InitLogger(fileName, level string) (log *Logger, err error) {
var (
logger *logrus.Logger
file *os.File
fileDir string
)
logger = logrus.New()
logger.SetReportCaller(true)
logger.SetFormatter(&logrus.JSONFormatter{})
fileDir = path.Dir(fileName)
fmt.Println(fileDir)
_, err = os.Stat(fileDir)
if os.IsNotExist(err) {
if err = os.MkdirAll(fileDir, os.ModePerm); err != nil {
logger.Fatal(err)
}
}
if file, err = os.OpenFile(fileName, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0766); err != nil {
logger.Error(err)
}
if level == "error" {
logger.SetLevel(logrus.ErrorLevel)
}
if level == "info" {
logger.SetLevel(logrus.InfoLevel)
}
if level == "warn" {
logger.SetLevel(logrus.WarnLevel)
}
if level == "fatal" {
logger.SetLevel(logrus.FatalLevel)
}
if level == "panic" {
logger.SetLevel(logrus.PanicLevel)
}
if level == "debug" {
logger.SetLevel(logrus.DebugLevel)
}
logger.Out = file
log = &Logger{
Log: logger,
}
return
}
//func (logger *Logger) Info(data, name string) {
// log.Println(runtime.Caller(0))
// logger.log.WithFields(logrus.Fields{"source": name, "status": 200}).Info(data)
//}
//
//func (logger *Logger) Error(data, name string) {
// logger.log.WithFields(logrus.Fields{"source": name, "status": 400}).Error(data)
//}
## 实时转写结果语法
CREATE TABLE `transfer_log`
(
`id` VARCHAR(64) PRIMARY KEY COMMENT '正式结果的id',
`user` VARCHAR(64) DEFAULT NULL COMMENT '用户名',
`sys_type` int(2) DEFAULT 0 COMMENT '1.语音操控 2.APP',
`meeting_id` VARCHAR(64) NOT NULL COMMENT '每个长连接连接的id',
`session_id` VARCHAR(64) NOT NULL COMMENT '服务端赋予每个长连接连接的id',
`texts` VARCHAR(1024) DEFAULT NULL COMMENT '正式结果',
`audio_file` VARCHAR(512) UNIQUE DEFAULT NULL COMMENT '对应音频文件的完整地址',
`started_at` TIMESTAMP DEFAULT NULL COMMENT '开始时间',
`created_at` TIMESTAMP DEFAULT NULL COMMENT '创建时间',
`updated_at` TIMESTAMP DEFAULT NULL COMMENT '更新时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
INSERT INTO `transfer_log` (`id`, `user`,`sys_type`, `meeting_id`, `session_id`, `texts`,`audio_file`,`started_at`,`created_at`,`updated_at`) VALUES ('1234567890','test1',0,'meeting_id1','sessiong_id1','从北京到上海的航线情况','/opt/huisheng/wav/audio/test1/meeting_id1/sessiong_id100000001.wav','2023-06-12 12:00:00','2023-06-12 12:00:00','2023-06-12 12:00:00');
INSERT INTO `transfer_log` (`id`, `user`,`sys_type`, `meeting_id`, `session_id`, `texts`,`audio_file`,`started_at`,`created_at`,`updated_at`) VALUES ('1234567891','test1',0,'meeting_id1','sessiong_id1','从北京到广州的航线情况','/opt/huisheng/wav/audio/test1/meeting_id1/sessiong_id100000002.wav','2023-06-12 12:00:20','2023-06-12 12:00:20','2023-06-12 12:00:20');
INSERT INTO `transfer_log` (`id`, `user`,`sys_type`, `meeting_id`, `session_id`, `texts`,`audio_file`,`started_at`,`created_at`,`updated_at`) VALUES ('1234567892','test1',0,'meeting_id1','sessiong_id1','从北京到深圳的航线情况','/opt/huisheng/wav/audio/test1/meeting_id1/sessiong_id100000003.wav','2023-06-12 12:00:30','2023-06-12 12:00:30','2023-06-12 12:00:30');
INSERT INTO `transfer_log` (`id`, `user`,`sys_type`, `meeting_id`, `session_id`, `texts`,`audio_file`,`started_at`,`created_at`,`updated_at`) VALUES ('1234567893','test1',0,'meeting_id1','sessiong_id1','从北京到成都的航线情况','/opt/huisheng/wav/audio/test1/meeting_id1/sessiong_id100000004.wav','2023-06-12 12:00:40','2023-06-12 12:00:40','2023-06-12 12:00:40');
## 需求解析结果sql
CREATE TABLE `parse_log`
(
`transfer_id` VARCHAR(64) NOT NULL UNIQUE COMMENT '正式结果的id,跟`transfer_log`的`id`匹配',
`parse_result` VARCHAR(1024) DEFAULT NULL COMMENT '需求解析结果,一般设置json格式',
`created_at` TIMESTAMP DEFAULT NULL COMMENT '创建时间',
`updated_at` TIMESTAMP DEFAULT NULL COMMENT '创建时间'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
INSERT INTO `parse_log` (`transfer_id`, `parse_result`,`created_at`,`updated_at`) VALUES ('1234567890','"{"intent":"","entities":[{"entity":"city","value":"北京"},{"entity":"city","value":"上海"}]}"','2023-06-12 12:00:00','2023-06-12 12:00:00');
INSERT INTO `parse_log` (`transfer_id`, `parse_result`,`created_at`,`updated_at`) VALUES ('1234567891','"{"intent":"","entities":[{"entity":"city","value":"北京"},{"entity":"city","value":"广州"}]}"','2023-06-12 12:00:20','2023-06-12 12:00:20');
INSERT INTO `parse_log` (`transfer_id`, `parse_result`,`created_at`,`updated_at`) VALUES ('1234567892','"{"intent":"","entities":[{"entity":"city","value":"北京"},{"entity":"city","value":"深圳"}]}"','2023-06-12 12:00:30','2023-06-12 12:00:30');
INSERT INTO `parse_log` (`transfer_id`, `parse_result`,`created_at`,`updated_at`) VALUES ('1234567893','"{"intent":"","entities":[{"entity":"city","value":"北京"},{"entity":"city","value":"成都"}]}"','2023-06-12 12:00:40','2023-06-12 12:00:40');
package main
import (
"fmt"
"gRPC-Raisound-Base-second-pass/initServer"
"gRPC-Raisound-Base-second-pass/server"
"github.com/gin-gonic/gin"
"github.com/soheilhy/cmux"
"log"
"net"
"time"
)
var Version = "This is the basic version of gRPC, the latest version updated on October 10, 2022.\nUpdated an issue where audio and text do not match."
func main() {
if initServer.Version {
log.Println(Version)
}
if !initServer.Version {
var (
err error
lis net.Listener
)
//server.ConfigMap["empty"] = b
if lis, err = net.Listen("tcp", fmt.Sprintf(":%v", initServer.ConfigMap["port"].(string))); err != nil {
log.Fatalf("failed to listen: %v", err)
}
log.Println("listen: ", fmt.Sprintf(":%v ,time: %v", initServer.ConfigMap["port"].(string), time.Now().String()))
cm := cmux.New(lis)
grpcL := cm.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
grpcServer := server.GrpcServer()
go func() {
if e := grpcServer.Serve(grpcL); e != nil {
log.Fatalf("failed to serve: %v", e)
}
}()
// http
router := gin.Default()
go func() {
httpL := cm.Match(cmux.HTTP1Fast())
router.GET("/getEnd/:meeting_id", server.GetEnd)
router.GET("/getAudioFile", server.GetAudioFile)
router.POST("/removeMeetingId", server.RemoveFile)
router.GET("/getAudioPath/:token/:aid/:bid", server.LoadFile)
router.GET("/loadAudioPath/:aid/:bid", server.LoadFile1)
_ = router.RunListener(httpL)
}()
_ = cm.Serve()
}
}
package otherHandler
import (
"bytes"
"crypto/md5"
"encoding/json"
"errors"
"fmt"
"github.com/sirupsen/logrus"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"strings"
"time"
)
// CheckToken TODO:校验token
func CheckToken(token, checkTokenURL string) (isYes bool, err error) {
var (
url string // 请求路由
jsonData []byte // 请求json数据
req *http.Request
resp *http.Response
resultBody []byte // 请求结果
resultMap map[string]interface{} // 请求结果数据转换位map
)
url = checkTokenURL
// 请求json数据格式
jsonMap := make(map[string]string)
jsonMap["token"] = token
if jsonData, err = json.Marshal(jsonMap); err != nil {
err = errors.New("json error")
log.Println(url, err)
return
}
// post请求,获取结果
if req, err = http.NewRequest("POST", url, bytes.NewBuffer(jsonData)); err != nil {
err = errors.New("request error")
log.Println(url, err)
return
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
if resp, err = client.Do(req); err != nil {
err = errors.New("response error")
log.Println(url, err)
return
}
if resultBody, err = ioutil.ReadAll(resp.Body); err != nil {
err = errors.New("read error")
log.Println(url, err)
return
}
log.Println("token response:", string(resultBody))
// 请求结果数据转换位map
if err = json.Unmarshal(resultBody, &resultMap); err != nil {
err = errors.New("[]byte to map error")
log.Println(url, err)
return
}
// 提取结果
if _, ok := resultMap["code"]; ok {
switch resultMap["code"].(type) {
case string:
if resultMap["code"].(string) == "200" {
isYes = true
} else {
err = errors.New("token error")
}
case float64:
if resultMap["code"].(float64) == float64(200) {
isYes = true
} else {
err = errors.New("token error")
}
}
} else {
isYes = false
err = errors.New("checking token error, please check server")
return ok, errors.New("checking token error, please check server")
}
return
}
// MD5
func MD5(str string) string {
data := []byte(str) //切片
has := md5.Sum(data)
md5str := fmt.Sprintf("%x", has) //将[]byte转成16进制
return md5str
}
// TODO:保存音频
func SaveAudioData(meetingId, sessionID, audioPath string, audioData []byte, dataNum int) (singleFileName string, errMsg error) {
var (
pcmPath string
err error
sFile *os.File
)
pcmPath = audioPath
// 确定文件格式
now := time.Now()
dataSubx := fmt.Sprintf("%d-%02d-%02d", now.Year(), now.Month(), now.Day())
fileDir := fmt.Sprintf("%v/%v/%v/%v", pcmPath, meetingId, sessionID, dataSubx)
sInt := fmt.Sprintf("%08d", dataNum)
sName := fmt.Sprintf("%v/%v/%v/%v/%v-%v.wav", pcmPath, meetingId, sessionID, dataSubx, sessionID, sInt)
singleFileName = sName
// 创建文件夹
_, err = os.Stat(fileDir)
if os.IsNotExist(err) {
if err = os.MkdirAll(fileDir, os.ModePerm); err != nil {
fmt.Println(err)
errMsg = err
return
}
}
waveHeader := pcmToWavHeader(1, 16000, 16, len(audioData))
// 将数据存入单独文件
if sFile, err = os.OpenFile(sName, os.O_RDONLY|os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0766); err != nil {
errMsg = err
return
}
if _, err = sFile.Write(waveHeader); err != nil {
if err = sFile.Close(); err != nil {
return
}
errMsg = err
return
}
if _, err = sFile.Write(audioData); err != nil {
if err = sFile.Close(); err != nil {
return
}
errMsg = err
return
}
if err = sFile.Close(); err != nil {
errMsg = err
return
}
return
}
// TODO:判断文件是否存在
func ExistsFile(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return true, err
}
// TODO: POST结构请求处理
func postHandler(URL string, reqJson string) (result map[string]interface{}, err error) {
var (
Url = URL
resp *http.Response
responseData []byte
)
result = make(map[string]interface{})
if resp, err = http.Post(Url, "application/json", strings.NewReader(reqJson)); err != nil {
logrus.Errorln(err.Error())
return
}
defer func(response *http.Response) {
if err = response.Body.Close(); err != nil {
logrus.Errorln(err.Error())
//initServer.Log.Log.WithFields(logrus.Fields{"source": "post request closing body error"}).Error(fmt.Sprintf("%v: %v", URL, err.Error()))
}
}(resp)
if resp.StatusCode != 200 {
err = errors.New("request error")
logrus.Errorln(err.Error())
//initServer.Log.Log.WithFields(logrus.Fields{"source": "post request status error"}).Error(fmt.Sprintf("%v: %v", URL, err.Error()))
}
if responseData, err = ioutil.ReadAll(resp.Body); err != nil {
logrus.Errorln(err.Error())
//initServer.Log.Log.WithFields(logrus.Fields{"source": "post request error"}).Error(fmt.Sprintf("%v: %v", URL, err.Error()))
}
if err = json.Unmarshal(responseData, &result); err != nil {
logrus.Errorln(err.Error())
//initServer.Log.Log.WithFields(logrus.Fields{"source": "post request body unmarshal error"}).Error(fmt.Sprintf("%v: %v", URL, err.Error()))
}
return
}
// TODO:获取热词文本地址
func GetHotWordPath(userId, hotWordURL string) (hotWordPath string, err error) {
var (
Url = hotWordURL
params = url.Values{}
responseData []byte
resp *http.Response
resultMap = make(map[string]interface{})
)
params["user_id"] = []string{userId}
if resp, err = http.PostForm(Url, params); err != nil {
return
}
defer func(response *http.Response) {
if response != nil {
_ = response.Body.Close()
}
}(resp)
if resp.StatusCode != 200 {
err = errors.New("network request error")
return
}
if responseData, err = ioutil.ReadAll(resp.Body); err != nil {
return
}
log.Println(string(responseData))
if err = json.Unmarshal(responseData, &resultMap); err != nil {
return
}
switch resultMap["code"].(type) {
case float64:
if resultMap["code"].(float64) == 200 {
hotWordPath = resultMap["data"].(map[string]interface{})["path"].(string)
} else {
err = errors.New("hot word text is not exiting")
}
case int:
if resultMap["code"].(float64) == 200 {
hotWordPath = resultMap["data"].(map[string]interface{})["path"].(string)
} else {
err = errors.New("hot word text is not exiting")
}
}
return
}
// TODO: 粤语
func CantoneseHandler(text, preText, digitConvertURLZHHK, punctuationURLZHHK, sensitiveWordURLZHHK string, usePunctuation, useSensitive, useDigitConvert bool) (result, preResult string, err error) {
var (
resultMap = make(map[string]interface{})
jsonStr string
)
// 转数字
if useDigitConvert {
jsonStr = fmt.Sprintf(`{"id":"","texts":"%v"}`, text)
if resultMap, err = postHandler(digitConvertURLZHHK, jsonStr); err == nil {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
}
}
}
}
}
// 标点
if usePunctuation {
temporaryResult := preText + text
// 请求json数据格式
jsonMap := make(map[string]interface{})
jsonMap["id"] = ""
if len([]rune(temporaryResult)) <= 512 && preText == "" {
jsonMap["texts"] = temporaryResult
jsonMap["pre_vad_length"] = -1
} else if len([]rune(temporaryResult)) <= 512 && preText != "" {
jsonMap["texts"] = temporaryResult
jsonMap["pre_vad_length"] = len([]rune(preText))
} else if len([]rune(temporaryResult)) > 512 && preText == "" {
jsonMap["texts"] = string([]rune(temporaryResult)[:512])
jsonMap["pre_vad_length"] = -1
} else {
jsonMap["texts"] = string([]rune(temporaryResult)[:512])
jsonMap["pre_vad_length"] = len([]rune(preText))
}
jsonData, _ := json.Marshal(jsonMap)
if resultMap, err = postHandler(punctuationURLZHHK, string(jsonData)); err != nil {
preText = ""
} else {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
preText = resultMap["pre_punc_result"].(string)
} else {
preText = ""
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
preText = resultMap["pre_punc_result"].(string)
} else {
preText = ""
}
}
}
}
}
// 敏感词
if useSensitive {
jsonStr = fmt.Sprintf(`{"id":"","texts":"%v"}`, text)
if resultMap, err = postHandler(sensitiveWordURLZHHK, jsonStr); err != nil {
} else {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
} else {
preText = ""
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
} else {
preText = ""
}
}
}
}
}
result = text
preResult = preText
return
}
// TODO: 中文
func ChineseHandler(text, preText, digitConvertURLZHCN, punctuationURLZHCN, sensitiveWordURLZHCN string, usePunctuation, useSensitive, useDigitConvert bool) (result, preResult string, err error) {
var (
resultMap = make(map[string]interface{})
jsonStr string
)
// 转数字
if useDigitConvert {
jsonStr = fmt.Sprintf(`{"id":"","texts":"%v"}`, text)
if resultMap, err = postHandler(digitConvertURLZHCN, jsonStr); err != nil {
} else {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
}
}
}
}
}
// 标点
if usePunctuation {
temporaryResult := preText + text
// 请求json数据格式
jsonMap := make(map[string]interface{})
jsonMap["id"] = ""
if len([]rune(temporaryResult)) <= 512 && preText == "" {
jsonMap["texts"] = temporaryResult
jsonMap["pre_vad_length"] = -1
} else if len([]rune(temporaryResult)) <= 512 && preText != "" {
jsonMap["texts"] = temporaryResult
jsonMap["pre_vad_length"] = len([]rune(preText))
} else if len([]rune(temporaryResult)) > 512 && preText == "" {
jsonMap["texts"] = string([]rune(temporaryResult)[:512])
jsonMap["pre_vad_length"] = -1
} else {
jsonMap["texts"] = string([]rune(temporaryResult)[:512])
jsonMap["pre_vad_length"] = len([]rune(preText))
}
jsonData, _ := json.Marshal(jsonMap)
if resultMap, err = postHandler(punctuationURLZHCN, string(jsonData)); err != nil {
preText = ""
} else {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
preText = resultMap["pre_punc_result"].(string)
} else {
preText = ""
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
preText = resultMap["pre_punc_result"].(string)
} else {
preText = ""
}
}
}
}
}
// 敏感词
if useSensitive {
jsonStr = fmt.Sprintf(`{"id":"","texts":"%v"}`, text)
if resultMap, err = postHandler(sensitiveWordURLZHCN, jsonStr); err != nil {
} else {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
} else {
preText = ""
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
} else {
preText = ""
}
}
}
}
}
result = text
preResult = preText
return
}
// TODO: 英文
func EnglishHandler(text, preText, EnPunctuationURL, e2nURL string, preVadLen int, usePunctuation, useC2a bool) (result, preResult string, preResultVadLen int, err error) {
var (
resultMap = make(map[string]interface{})
jsonStr string
)
if usePunctuation {
temporaryResult := preText + " " + text
// 请求json数据格式
jsonMap := make(map[string]interface{})
jsonMap["id"] = ""
jsonMap["texts"] = temporaryResult
if preVadLen != 0 {
jsonMap["pre_vad_length"] = preVadLen
} else {
jsonMap["pre_vad_length"] = -1
}
jsonData, _ := json.Marshal(jsonMap)
if resultMap, err = postHandler(EnPunctuationURL, string(jsonData)); err != nil {
preText = ""
} else {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
preText = resultMap["pre_punc_result"].(string)
switch resultMap["pre_vad_length"].(type) {
case float64:
preResultVadLen = int(resultMap["pre_vad_length"].(float64))
case int:
preResultVadLen = resultMap["pre_vad_length"].(int)
}
} else {
preText = ""
preResultVadLen = 0
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
preText = resultMap["pre_punc_result"].(string)
switch resultMap["pre_vad_length"].(type) {
case float64:
preResultVadLen = int(resultMap["pre_vad_length"].(float64))
case int:
preResultVadLen = resultMap["pre_vad_length"].(int)
}
} else {
preText = ""
preResultVadLen = 0
}
}
}
}
}
if useC2a {
jsonStr = fmt.Sprintf(`{"id":"","text":"%v"}`, text)
if resultMap, err = postHandler(e2nURL, jsonStr); err == nil {
if resultMap != nil {
switch resultMap["status"].(type) {
case float64:
if resultMap["status"].(float64) == float64(200) {
text = resultMap["result"].(string)
} else {
preText = ""
}
case int:
if resultMap["status"].(int) == 200 {
text = resultMap["result"].(string)
} else {
preText = ""
}
}
}
}
}
result = text
preResult = preText
return
}
type PostReq struct {
Id int `json:"id"`
Texts string `json:"texts"`
Mode int `json:"mode"`
Backup map[string]interface{} `json:"backup"`
}
type PostResp struct {
Status int `json:"status"`
Id int `json:"id"`
Result string `json:"result"`
Backup map[string]interface{} `json:"backup"`
}
func PostGet(req PostReq, url string) (resp *PostResp, err error) {
var (
jsonByte []byte
reqHttp *http.Request
respHttp *http.Response
respBody []byte
client = &http.Client{
Timeout: time.Duration(500) * time.Millisecond,
}
)
if jsonByte, err = json.Marshal(req); err != nil {
return
}
//logrus.Println("req:", string(jsonByte))
if reqHttp, err = http.NewRequest("POST", url, bytes.NewBuffer(jsonByte)); err != nil {
return
}
reqHttp.Header.Set("Content-Type", "application/json")
if respHttp, err = client.Do(reqHttp); err != nil {
logrus.Errorln(err.Error())
return
}
defer func() {
if respHttp.Body != nil {
_ = respHttp.Body.Close()
}
}()
if respBody, err = ioutil.ReadAll(respHttp.Body); err != nil {
logrus.Errorln(err.Error())
return
}
//logrus.Println(string(respBody))
if respHttp.StatusCode == 200 {
resp = &PostResp{}
if err = json.Unmarshal(respBody, resp); err != nil {
logrus.Errorln(err.Error())
return
}
} else {
err = errors.New(respHttp.Status)
logrus.Errorln(err.Error())
}
//logrus.Println(err, fmt.Sprintf("status=%v,result=%v,backup=%v,error=%v", resp.Status, resp.Result, resp.Backup, err.Error()))
return
}
package otherHandler
import (
"errors"
"github.com/sirupsen/logrus"
"time"
)
type LogData struct {
Id interface{}
User interface{}
SysType interface{}
MeetingId interface{}
SessionId interface{}
Texts interface{}
AudioFile interface{}
StartedAt interface{}
CreatedAt interface{}
UpdatedAt interface{}
End bool
}
type LogDataHandler struct {
dataCache chan LogData
mysqlCon *MysqlConn
}
func InitLog(mysqlIp, mysqlPort, mysqlUser, mysqlPasswd, mysqlDatabase string, dataCacheNum int) (log *LogDataHandler) {
var (
conn *MysqlConn
)
conn = InitMysqlDb(mysqlIp, mysqlPort, mysqlUser, mysqlPasswd, mysqlDatabase)
log = &LogDataHandler{
dataCache: make(chan LogData, dataCacheNum),
mysqlCon: conn,
}
go func() {
for {
log.insertDataToMysql()
}
}()
return
}
func (Log *LogDataHandler) SetData(data LogData) (err error) {
logrus.Println(data)
select {
case Log.dataCache <- data:
default:
err = errors.New("the database has crashed and the cache space is full")
}
return
}
func (Log *LogDataHandler) insertDataToMysql(data ...LogData) {
var (
getData LogData
cacheData []LogData
sql = "INSERT INTO `transfer_log` (`id`,`user`,`sys_type`,`meeting_id`,`session_id`,`texts`,`audio_file`,`started_at`,`created_at`,`updated_at`) VALUES (?,?,?,?,?,?,?,?,?,?); "
columnData [][]interface{}
err error
)
if len(data) > 0 {
for _, val := range data {
//if idx == len(data)-1 {
// sql = sql + "(?,?,?,?,?,?,?,?,?,?);"
//} else {
// sql = sql + "(?,?,?,?,?,?,?,?,?,?),"
//}
columnData = append(columnData, []interface{}{val.Id, val.User, val.SysType, val.MeetingId, val.SessionId, val.Texts, val.AudioFile, val.StartedAt, val.CreatedAt, val.UpdatedAt})
}
if err = Log.mysqlCon.InsertData(sql, columnData...); err != nil {
logrus.Errorln(err)
time.Sleep(5 * time.Second)
Log.insertDataToMysql(data...)
}
} else {
for {
select {
case getData = <-Log.dataCache:
}
if len(cacheData) == 10 || getData.End {
break
}
//logrus.Println(getData)
cacheData = append(cacheData, getData)
}
Log.insertDataToMysql(cacheData...)
}
return
}
package otherHandler
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/sirupsen/logrus"
"log"
"sync"
"time"
)
type MysqlConn struct {
dbConn *sql.DB
ip string
port string
user string
passwd string
database string
restartConn bool
lock sync.Mutex
}
func InitMysqlDb(ip, port, user, passwd, database string) (conn *MysqlConn) {
var (
db *sql.DB
err error
dsn string
)
dsn = fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True", user, passwd, ip, port, database)
log.Println(dsn)
if db, err = sql.Open("mysql", dsn); err != nil {
logrus.Errorln(err)
time.Sleep(5 * time.Second)
return InitMysqlDb(ip, port, user, passwd, database)
}
if err = db.Ping(); err != nil {
logrus.Errorln(err)
time.Sleep(5 * time.Second)
return InitMysqlDb(ip, port, user, passwd, database)
}
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(2)
conn = &MysqlConn{
dbConn: db,
ip: ip,
port: port,
user: user,
passwd: passwd,
database: database,
}
log.Println("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH")
return
}
func (db *MysqlConn) InsertData(insertSQL string, data ...[]interface{}) (err error) {
//var (
// result sql.Result
//)
if db.dbConn != nil {
if err = db.dbConn.Ping(); err != nil {
db.lock.Lock()
if !db.restartConn {
db.restartConn = true
dbTemp := InitMysqlDb(db.ip, db.port, db.user, db.passwd, db.database)
db.dbConn = dbTemp.dbConn
}
db.lock.Unlock()
go func() {
time.Sleep(3 * time.Second)
db.restartConn = false
}()
return db.InsertData(insertSQL, data...)
}
tx, e := db.dbConn.Begin()
if e != nil {
logrus.Errorln(e)
time.Sleep(1 * time.Second)
return db.InsertData(insertSQL, data...)
}
stmt, e1 := tx.Prepare(insertSQL)
if e1 != nil {
logrus.Errorln(e1)
time.Sleep(1 * time.Second)
return db.InsertData(insertSQL, data...)
}
var errData [][]interface{}
for _, val := range data {
if _, err = stmt.Exec(val...); err != nil {
logrus.Errorln(err)
//time.Sleep(1 * time.Second)
errData = append(errData, val)
}
//if row, _ := result.LastInsertId(); row == 0 {
// logrus.Errorln("cannot insert data")
// errData = append(errData, val)
//}
}
_ = tx.Commit()
if len(errData) > 0 {
return db.InsertData(insertSQL, errData...)
}
} else {
db.lock.Lock()
if !db.restartConn {
db.restartConn = true
dbTemp := InitMysqlDb(db.ip, db.port, db.user, db.passwd, db.database)
db.dbConn = dbTemp.dbConn
}
db.lock.Unlock()
go func() {
time.Sleep(3 * time.Second)
db.restartConn = false
}()
return db.InsertData(insertSQL, data...)
}
return
}
package otherHandler
import (
"crypto/md5"
"fmt"
"github.com/garyburd/redigo/redis"
"github.com/sirupsen/logrus"
)
type RdbStruct struct {
rDbConn redis.Conn
channel string
server string
}
func InitRdb(channel, server string) (Db *RdbStruct, err error) {
var (
rDb redis.Conn
)
if rDb, err = redis.Dial("tcp", server); err != nil {
logrus.Errorln("connecting redis error")
return
}
Db = &RdbStruct{
rDbConn: rDb,
channel: channel,
server: server,
}
return
}
func (rdb *RdbStruct) Set(key string, value int) (err error) {
key = "meetingId:" + fmt.Sprintf("%x", md5.Sum([]byte(key)))
if _, err = rdb.rDbConn.Do("SET", key, value); err != nil {
logrus.Errorln("Publish data redis channel error")
var (
rDb redis.Conn
)
if rDb, err = redis.Dial("tcp", rdb.server); err != nil {
return
}
if _, err = rDb.Do("SET", key, value); err != nil {
return
}
rdb.rDbConn = rDb
}
return
}
func (rdb *RdbStruct) PubMsg(msg string) (err error) {
if _, err = rdb.rDbConn.Do("Publish", rdb.channel, msg); err != nil {
logrus.Errorln("Publish data redis channel error")
var (
rDb redis.Conn
)
if rDb, err = redis.Dial("tcp", rdb.server); err != nil {
return
}
if _, err = rDb.Do("Publish", rdb.channel, msg); err != nil {
return
}
rdb.rDbConn = rDb
}
return
}
func (rdb *RdbStruct) LeftPubMsg(msg string) (err error) {
if _, err = rdb.rDbConn.Do("lpush", "audioQueue", msg); err != nil {
logrus.Errorln("lPublish data redis channel error")
var (
rDb redis.Conn
)
if rDb, err = redis.Dial("tcp", rdb.server); err != nil {
return
}
if _, err = rdb.rDbConn.Do("lpush", "audioQueue", msg); err != nil {
return
}
rdb.rDbConn = rDb
}
return
}
func (rdb *RdbStruct) RedisClose() {
var err error
if err = rdb.rDbConn.Close(); err != nil {
logrus.Errorln("closing redis connecting error")
}
}
package otherHandler
import (
"fmt"
"io/ioutil"
"os"
)
type WavStruct struct {
file *os.File
meetingId string
EFile string
audioLength int
isClose bool
}
// InitSaveWave TODO:初始化wave文件
func InitSaveWave(meetingId, audioPath string) (wav *WavStruct, err error) {
var (
file *os.File
audioLength int
)
// 创建文件夹
pcmPath := audioPath
// 确定文件格式
fileDir := fmt.Sprintf("%v/%v", pcmPath, meetingId)
eName := fmt.Sprintf("%v/%vf.wav", fileDir, meetingId)
if exist, _ := ExistsFile(eName); exist {
content, _ := ioutil.ReadFile(eName)
audioLength = len(content)
}
_, err = os.Stat(fileDir)
if os.IsNotExist(err) {
if err = os.MkdirAll(fileDir, os.ModePerm); err != nil {
return
}
}
// 将数据存入总文件
if file, err = os.OpenFile(eName, os.O_RDONLY|os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0766); err != nil {
return
}
wav = &WavStruct{
file: file,
meetingId: meetingId,
EFile: eName,
audioLength: audioLength,
}
return
}
func (w *WavStruct) SaveData(data []byte) (filePath string, err error) {
if _, err = w.file.Write(data); err != nil {
if w.file, err = os.OpenFile(w.EFile, os.O_RDONLY|os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0766); err != nil {
return
}
if _, err = w.file.Write(data); err != nil {
return
}
}
filePath = w.EFile
w.audioLength = w.audioLength + len(data)
return
}
func (w *WavStruct) CloseWav() (err error) {
//_ ,_ = w.file.Seek(44,0)
//w.file.WriteAt()
if !w.isClose {
w.isClose = true
if err = w.file.Close(); err != nil {
}
file1, _ := os.OpenFile(w.EFile, os.O_RDWR, os.ModePerm)
l, _ := file1.Seek(0, 0)
waveHeader := pcmToWavHeader(1, 16000, 16, w.audioLength)
_, _ = file1.WriteAt(waveHeader, l)
_ = file1.Close()
}
return
}
/*
*
dst:二进制字符串
numChannel:1=单声道,2=多声道
sampleRate:采样率 8000/16000
*/
func pcmToWavHeader(numChannel, sampleRate, bitsPerSample, audioLen int) (wavHeader []byte) {
longSampleRate := sampleRate
byteRate := bitsPerSample * sampleRate * numChannel / 8
totalAudioLen := audioLen
totalDataLen := totalAudioLen + 36
var header = make([]byte, 44)
// RIFF/WAVE header
header[0] = 'R'
header[1] = 'I'
header[2] = 'F'
header[3] = 'F'
header[4] = byte(totalDataLen & 0xff)
header[5] = byte((totalDataLen >> 8) & 0xff)
header[6] = byte((totalDataLen >> 16) & 0xff)
header[7] = byte((totalDataLen >> 24) & 0xff)
//WAVE
header[8] = 'W'
header[9] = 'A'
header[10] = 'V'
header[11] = 'E'
// 'fmt ' chunk
header[12] = 'f'
header[13] = 'm'
header[14] = 't'
header[15] = ' '
// 4 bytes: size of 'fmt ' chunk
header[16] = 16
header[17] = 0
header[18] = 0
header[19] = 0
// format = 1
header[20] = 1
header[21] = 0
header[22] = byte(numChannel)
header[23] = 0
header[24] = byte(longSampleRate & 0xff)
header[25] = byte((longSampleRate >> 8) & 0xff)
header[26] = byte((longSampleRate >> 16) & 0xff)
header[27] = byte((longSampleRate >> 24) & 0xff)
header[28] = byte(byteRate & 0xff)
header[29] = byte((byteRate >> 8) & 0xff)
header[30] = byte((byteRate >> 16) & 0xff)
header[31] = byte((byteRate >> 24) & 0xff)
// block align
header[32] = byte(numChannel * bitsPerSample / 8)
header[33] = 0
// bits per sample
header[34] = byte(bitsPerSample)
header[35] = 0
//data
header[36] = 'd'
header[37] = 'a'
header[38] = 't'
header[39] = 'a'
header[40] = byte(totalAudioLen & 0xff)
header[41] = byte((totalAudioLen >> 8) & 0xff)
header[42] = byte((totalAudioLen >> 16) & 0xff)
header[43] = byte((totalAudioLen >> 24) & 0xff)
wavHeader = header
return
}
package otherHandler
import (
"github.com/bwmarrin/snowflake"
"github.com/sirupsen/logrus"
"time"
)
type SnowflakeBase struct {
node *snowflake.Node
}
func NewSnowFlake(machineId int64) (snow *SnowflakeBase) {
var (
err error
node *snowflake.Node
)
snowflake.Epoch = time.Now().UnixMicro() / 1e6
if node, err = snowflake.NewNode(machineId); err != nil {
logrus.Fatalln(err.Error())
}
snow = &SnowflakeBase{
node: node,
}
return
}
func (snow *SnowflakeBase) GetIds(number int) (ids []string, err error) {
for i := 0; i < number; i++ {
ids = append(ids, snow.node.Generate().String())
}
return
}
package server
import (
"encoding/json"
"fmt"
serverPb "gRPC-Raisound-Base-second-pass/Raisound-protobuf"
"gRPC-Raisound-Base-second-pass/initServer"
"gRPC-Raisound-Base-second-pass/otherHandler"
"gRPC-Raisound-Base-second-pass/serverHandler"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"io/ioutil"
"os"
"regexp"
"strconv"
"strings"
"time"
)
func GrpcServer() (grpcServer *grpc.Server) {
var keep = keepalive.EnforcementPolicy{
MinTime: 5 * time.Second, // If a client pings more than once every 5 seconds, terminate the connection
PermitWithoutStream: true, // Allow pings even when there are no active streams
}
//grpc.KeepaliveEnforcementPolicy(kaep),
var kasp = keepalive.ServerParameters{
//MaxConnectionIdle: 15 * time.Second, // If a client is idle for 15 seconds, send a GOAWAY
//MaxConnectionAge: 30 * time.Second, // If any connection is alive for more than 30 seconds, send a GOAWAY
MaxConnectionAgeGrace: 5 * time.Second, // Allow 5 seconds for pending RPCs to complete before forcibly closing connections
Time: 5 * time.Second, // Ping the client if it is idle for 5 seconds to ensure the connection is still active
Timeout: 1 * time.Second, // Wait 1 second for the ping ack before assuming the connection is dead
}
grpcServer = grpc.NewServer(grpc.KeepaliveEnforcementPolicy(keep), grpc.KeepaliveParams(kasp))
if server, err := serverHandler.InitServer(); err != nil {
return
} else {
serverPb.RegisterRaisoundSpeechServer(grpcServer, server)
}
return
}
func GetAudioFile(ctx *gin.Context) {
token := ctx.Request.Header.Get("token")
if token == "" {
ctx.JSONP(400, gin.H{
"code": 400,
"description": "token is empty.",
},
)
} else {
if yes, err := otherHandler.CheckToken(token, initServer.ConfigMap["checkTokenURL"].(string)); yes && err == nil {
meetingID := ctx.Query("meeting_id")
if meetingID == "" {
ctx.JSONP(400, gin.H{
"code": 400,
"description": "The parameter value is missing.",
},
)
} else {
audioFile := fmt.Sprintf("%v/%v/%vf.wav", initServer.ConfigMap["audioPath"].(string), meetingID, meetingID)
if exit, _ := otherHandler.ExistsFile(audioFile); exit {
ctx.JSONP(200, gin.H{
"code": 200,
"data": fmt.Sprintf("http://%v/getAudioPath/%v/%v/%vf.wav", ctx.Request.Host, token, meetingID, meetingID),
"description": "succeed",
},
)
} else {
ctx.JSONP(404, gin.H{
"code": 404,
"description": "The file does not exist.",
},
)
}
}
} else if !yes && err == nil {
ctx.JSONP(401, gin.H{
"code": 401,
"description": "token error.",
},
)
} else if err != nil {
ctx.JSONP(404, gin.H{
"code": 404,
"description": err.Error(),
},
)
}
}
}
func GetEnd(ctx *gin.Context) {
meetingId := ctx.Param("meeting_id")
if meetingId == "" {
ctx.JSONP(
400,
gin.H{
"code": 400,
"description": "the meeting_id is empty,please check the value of meeting_id.",
})
} else {
reCompile, _ := regexp.Compile("_\\d{0,3}$")
var (
tempMeetingId string
tempSpeaker string
)
if reCompile.Match([]byte(meetingId)) {
tempMeetingId = reCompile.ReplaceAllString(meetingId, "")
tempSpeaker = strings.Replace(reCompile.FindString(meetingId), "_", "", -1)
} else {
tempMeetingId = meetingId
tempSpeaker = "false"
}
audioFile := fmt.Sprintf("%v/%v/%vf.wav", initServer.ConfigMap["audiioPath"].(string), meetingId, meetingId)
if exit, _ := otherHandler.ExistsFile(audioFile); exit {
var (
publicMsg = make(map[string]interface{})
endMsg = make(map[string]interface{})
wavStruct *otherHandler.WavStruct
rb *otherHandler.RdbStruct
err error
)
content, _ := ioutil.ReadFile(audioFile)
duration := len(content) - 44
if content[0] == 'R' && content[1] == 'I' && content[2] == 'F' && content[3] == 'F' {
} else {
if wavStruct, err = otherHandler.InitSaveWave(meetingId, initServer.ConfigMap["audioPath"].(string)); err != nil {
ctx.JSONP(400, gin.H{
"code": 400,
"description": err.Error(),
},
)
}
if wavStruct != nil {
_ = wavStruct.CloseWav()
}
}
if rb, err = otherHandler.InitRdb(initServer.ConfigMap["redisChannel"].(string), initServer.ConfigMap["redisURL"].(string)); err != nil {
ctx.JSONP(400, gin.H{
"code": 400,
"description": err.Error(),
},
)
}
if rb != nil {
timestamp, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", float64(time.Now().UnixMilli())/float64(32000)), 64)
durationTime, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", float64(duration)/float64(1000)), 64)
publicMsg["timestamp"] = timestamp
publicMsg["url"] = ""
publicMsg["raw_text"] = ""
publicMsg["end_of_speech"] = 1
publicMsg["pcmtime"] = 0.0
publicMsg["duration"] = durationTime
publicMsg["meeting_id"] = tempMeetingId
publicMsg["session_id"] = ""
publicMsg["entire_file_path"] = audioFile
publicMsg["end"] = 1
publicMsg["speaker"] = fmt.Sprintf("%v", tempSpeaker) //speaker
data, _ := json.Marshal(publicMsg)
_ = rb.PubMsg(string(data))
endMsg["speaker"] = tempSpeaker
endMsg["meeting_id"] = tempMeetingId
endMsg["file_path"] = audioFile
jsonQueueData, _ := json.Marshal(endMsg)
_ = rb.LeftPubMsg(string(jsonQueueData))
rb.RedisClose()
ctx.JSONP(200, gin.H{
"code": 200,
"description": "succeed",
"meeting_id": meetingId,
})
}
} else {
ctx.JSONP(403, gin.H{
"code": 403,
"description": "can find the meeting",
},
)
}
}
}
func LoadFile1(ctx *gin.Context) {
fileIdA := ctx.Param("aid")
fileIdB := ctx.Param("bid")
audioFile := fmt.Sprintf("%v/%v/%v", initServer.ConfigMap["audioPath"].(string), fileIdA, fileIdB)
ok, _ := otherHandler.ExistsFile(audioFile)
if !ok {
ctx.JSONP(404, gin.H{
"code": 404,
"description": "the file is not existing.",
})
return
}
ctx.Header("Content-Type", "application/octet-stream")
ctx.Header("Content-Disposition", "attachment; filename="+audioFile)
ctx.Header("Content-Transfer-Encoding", "binary")
ctx.FileAttachment(audioFile, fileIdB)
}
func LoadFile(ctx *gin.Context) {
token := ctx.Param("token")
fileIdA := ctx.Param("aid")
fileIdB := ctx.Param("bid")
if yes, err := otherHandler.CheckToken(token, initServer.ConfigMap["checkTokenURL"].(string)); yes && err == nil {
audioFile := fmt.Sprintf("%v/%v/%v", initServer.ConfigMap["audioPath"].(string), fileIdA, fileIdB)
ctx.Header("Content-Type", "application/octet-stream")
ctx.Header("Content-Disposition", "attachment; filename="+audioFile)
ctx.Header("Content-Transfer-Encoding", "binary")
ctx.FileAttachment(audioFile, fileIdB)
} else if !yes && err == nil {
ctx.JSONP(404, gin.H{
"code": 404,
"description": "file path error.",
},
)
} else {
if err != nil {
if err.Error() != "checking token error, please check server" {
ctx.JSONP(403, gin.H{
"code": 403,
"description": "The address is invalid",
},
)
} else {
ctx.JSONP(400, gin.H{
"code": 400,
"description": err.Error(),
},
)
}
}
}
}
type reqBody struct {
MeetingId string `json:"meeting_id"`
}
func RemoveFile(ctx *gin.Context) {
var (
reqData = &reqBody{}
err error
)
if err = ctx.BindJSON(reqData); err != nil {
ctx.JSONP(400, gin.H{
"status": 400,
"desc": err.Error(),
})
return
}
//if len(strings.Split(initServer.ConfigMap["audioPath"].(string),""))
if reqData.MeetingId == "" || initServer.ConfigMap["audioPath"].(string) == "" {
ctx.JSONP(400, gin.H{
"status": 400,
"desc": "wrong root directory or meeting_id.",
})
return
}
meetingIdName := fmt.Sprintf("%v/%v", initServer.ConfigMap["audioPath"].(string), reqData.MeetingId)
if err = os.RemoveAll(meetingIdName); err != nil {
ctx.JSONP(400, gin.H{
"status": 400,
"desc": err.Error(),
})
return
}
ctx.JSONP(200, gin.H{
"status": 200,
"desc": "meeting data is removed successfully",
})
return
}
package serverHandler
import (
"context"
"errors"
serverPb "gRPC-Raisound-Base-second-pass/Raisound-protobuf"
)
func (server *Service) HeartBeat(cxt context.Context, req *serverPb.HeartBeatConfig) (resp *serverPb.HeartBeatResponse, err error) {
if ok := server.checkSessionId(req.GetSessionId()); ok {
//_ = server.delete(req.GetSessionId())
resp = &serverPb.HeartBeatResponse{
Code: 200,
SessionId: req.GetSessionId(),
Description: "HeartBeat",
}
} else {
resp = &serverPb.HeartBeatResponse{
Code: 400,
SessionId: req.GetSessionId(),
Description: "Pool connections are not logged",
}
err = errors.New("pool connections are not logged")
}
return
}
package serverHandler
import (
"context"
"errors"
"fmt"
serverPb "gRPC-Raisound-Base-second-pass/Raisound-protobuf"
"gRPC-Raisound-Base-second-pass/initServer"
"gRPC-Raisound-Base-second-pass/otherHandler"
"github.com/gofrs/uuid"
"github.com/sirupsen/logrus"
"log"
"strings"
"time"
)
// InitStreamingASR(context.Context, *raisound.InitConfig) (*raisound.InitResponse, error)
func (server *Service) InitStreamingASR(cxt context.Context, req *serverPb.InitConfig) (resp *serverPb.InitResponse, err error) {
info := make(map[string]interface{})
if req.GetLang() != "" {
if req.GetLang() == "ZH-CN" || req.GetLang() == "ZH-HK" || req.GetLang() == "EN" {
info["language"] = req.GetLang()
} else {
info["language"] = initServer.ConfigMap["defaultLanguage"].(string)
}
} else {
info["language"] = initServer.ConfigMap["defaultLanguage"].(string)
}
if req.GetConnId() == "" {
info["userId"] = initServer.ConfigMap["hotWord-ZH-CN"].(string)
} else {
initServer.Log.Log.WithFields(logrus.Fields{"source": "get user_id"}).Info(req.GetConnId())
if hotWordPath, e := otherHandler.GetHotWordPath(req.GetConnId(), initServer.ConfigMap["hotWordURL"].(string)); e != nil {
initServer.Log.Log.WithFields(logrus.Fields{"source": "get hot word path error"}).Error(fmt.Sprintf(`{"user_id":"%v","error":"%v"}`, req.GetConnId(), e.Error()))
log.Println("get hot word path error:", e.Error())
info["userId"] = initServer.ConfigMap["hotWord-ZH-CN"].(string)
} else {
initServer.Log.Log.WithFields(logrus.Fields{"source": "hot word Path"}).Info(hotWordPath)
log.Println("hot word Path:", hotWordPath)
if hotWordPath != "" {
info["userId"] = hotWordPath
} else {
if req.GetLang() == "ZH-CN" {
info["userId"] = initServer.ConfigMap["hotWord-ZH-CN"].(string)
} else if req.GetLang() == "ZH-HK" {
info["userId"] = initServer.ConfigMap["hotWord-ZH-HK"].(string)
} else if req.GetLang() == "EN" {
info["userId"] = initServer.ConfigMap["hotWord-EN"].(string)
} else {
info["userId"] = initServer.ConfigMap["hotWord-ZH-CN"].(string)
}
}
}
}
sessionId, _ := uuid.NewV1()
if req.GetMeetingId() != "" {
log.Println(req.GetMeetingId())
splitMeeting := strings.Split(req.GetMeetingId(), "@")
info["meetingId"] = splitMeeting[0]
info["user"] = ""
info["sysType"] = 1
if len(splitMeeting) == 2 {
if splitMeeting[1] == "app" {
info["sysType"] = 2
}
}
if len(splitMeeting) > 2 {
if splitMeeting[1] == "app" {
info["sysType"] = 2
}
info["user"] = splitMeeting[2]
}
} else {
meetingId, _ := uuid.NewV4()
info["meetingId"] = meetingId.String()
info["user"] = ""
info["sysType"] = 1
}
if req.GetInterOuterFlag() != 1 {
if req.GetUser() == "admin" && req.GetPasswd() == "123456" {
info["time"] = time.Now().Unix()
info["sessionId"] = sessionId.String()
info["sensitiveFlag"] = req.GetSensitiveFlag()
info["puncFlag"] = req.GetPuncFlag()
info["numConvertFlag"] = req.GetNumConvertFlag()
_ = server.Add(sessionId.String(), info)
resp = &serverPb.InitResponse{
Code: 200,
SessionId: sessionId.String(),
Description: fmt.Sprintf(`{"status":200,"description":"Initialization succeeded","meeting_id":"%v"}`, info["meetingId"].(string)),
}
} else {
resp = &serverPb.InitResponse{
Code: 400,
SessionId: sessionId.String(),
Description: `{"status":400,"description":"user or the password is incorrect or invalid"}`,
}
err = errors.New("user or the password is incorrect or invalid")
}
} else {
log.Println("get the token:", req.Token)
if ok, _ := otherHandler.CheckToken(req.Token, initServer.ConfigMap["checkTokenURL"].(string)); ok {
info["time"] = time.Now().Unix()
info["sessionId"] = sessionId.String()
info["sensitiveFlag"] = req.GetSensitiveFlag()
info["puncFlag"] = req.GetPuncFlag()
info["numConvertFlag"] = req.GetNumConvertFlag()
_ = server.Add(sessionId.String(), info)
resp = &serverPb.InitResponse{
Code: 200,
SessionId: sessionId.String(),
Description: fmt.Sprintf(`{"status":200,"description":"Initialization succeeded","meeting_id":"%v"}`, info["meetingId"].(string)),
}
} else {
resp = &serverPb.InitResponse{
Code: 400,
SessionId: "",
Description: `{"status":400,"description":"token is incorrect or invalid"}`,
}
err = errors.New("token is incorrect or invalid")
}
}
log.Println("get Session:", sessionId.String())
log.Println("session info:", server.ConnInfo)
return
}
package serverHandler
import (
"context"
"errors"
serverPb "gRPC-Raisound-Base-second-pass/Raisound-protobuf"
)
func (server *Service) RelStreamingASR(cxt context.Context, req *serverPb.RelConfig) (resp *serverPb.RelResponse, err error) {
if ok := server.checkSessionId(req.GetSessionId()); ok {
_ = server.delete(req.GetSessionId())
resp = &serverPb.RelResponse{
Code: 200,
SessionId: req.GetSessionId(),
Description: "Release successfully",
}
//err = errors.New("release successfully")
} else {
resp = &serverPb.RelResponse{
Code: 400,
SessionId: req.GetSessionId(),
Description: "Pool connections are not logged",
}
err = errors.New("pool connections are not logged")
}
return
}
package serverHandler
import (
"bytes"
"encoding/json"
"errors"
"fmt"
serverPb "gRPC-Raisound-Base-second-pass/Raisound-protobuf"
"gRPC-Raisound-Base-second-pass/engineServer"
"gRPC-Raisound-Base-second-pass/initServer"
"gRPC-Raisound-Base-second-pass/otherHandler"
"github.com/sirupsen/logrus"
"regexp"
"strconv"
"strings"
"time"
)
type Stream struct {
engine *engineServer.Engine
wave *otherHandler.WavStruct
rDb *otherHandler.RdbStruct
audioBuff bytes.Buffer
inChan chan []byte
isCloseInChan bool
outChan chan []byte
isCloseOutChan bool
closeChan chan []byte
isCloseCloseChan bool
language string
sessionId string
entireMeetingId string
meetingId string
speaker string
punctuation bool
digit bool
sensitive bool
dataIndex int32
isEnd bool
sysType interface{}
user string
startTime time.Time
isTime bool
}
func InitStream(connInfo map[string]interface{}) (stream *Stream, err error) {
var (
conn *engineServer.Engine
wave *otherHandler.WavStruct
rDb *otherHandler.RdbStruct
language string
entireMeetingId string
meetingId string
speaker string
sessionId string
punctuation bool
digit bool
sensitive bool
sysType interface{}
user string
startTime = time.Now()
)
sysType = connInfo["sysType"]
user = connInfo["user"].(string)
language = connInfo["language"].(string)
entireMeetingId = connInfo["meetingId"].(string)
sessionId = connInfo["sessionId"].(string)
punctuation = !connInfo["puncFlag"].(bool)
digit = !connInfo["numConvertFlag"].(bool)
sensitive = !connInfo["sensitiveFlag"].(bool)
reCompile, _ := regexp.Compile("_\\d{0,3}$")
if reCompile.Match([]byte(entireMeetingId)) {
meetingId = reCompile.ReplaceAllString(entireMeetingId, "")
speaker = strings.Replace(reCompile.FindString(entireMeetingId), "_", "", -1)
} else {
meetingId = entireMeetingId
speaker = "false"
}
if wave, err = otherHandler.InitSaveWave(entireMeetingId, initServer.ConfigMap["audioPath"].(string)); err != nil {
return
}
if rDb, err = otherHandler.InitRdb(initServer.ConfigMap["redisChannel"].(string), initServer.ConfigMap["redisURL"].(string)); err != nil {
return
}
if conn, err = engineServer.InitEngine(language, connInfo["userId"].(string)); err != nil {
return
}
stream = &Stream{
engine: conn,
wave: wave,
rDb: rDb,
inChan: make(chan []byte, 1024),
outChan: make(chan []byte, 1024),
closeChan: make(chan []byte, 1),
language: language,
sessionId: sessionId,
entireMeetingId: entireMeetingId,
meetingId: meetingId,
speaker: speaker,
punctuation: punctuation,
digit: digit,
sensitive: sensitive,
dataIndex: 1,
sysType: sysType,
user: user,
startTime: startTime,
}
go stream.inChan2EngineLoop()
go stream.Engine2OutChanLoop()
return
}
func (stream *Stream) CloseChan() {
if stream.isEnd {
if stream.engine != nil {
_ = stream.engine.CloseEngine()
}
} else {
time.Sleep(500 * time.Millisecond)
_ = stream.engine.CloseEngine()
}
if !stream.isCloseInChan {
stream.isCloseInChan = true
close(stream.inChan)
}
time.Sleep(1 * time.Second)
if !stream.isCloseOutChan {
stream.isCloseOutChan = true
}
if !stream.isCloseCloseChan {
stream.isCloseCloseChan = true
close(stream.closeChan)
}
}
func (stream *Stream) WriteMsg(data []byte) (err error) {
if !stream.isCloseInChan {
select {
case stream.inChan <- data:
}
} else {
err = errors.New("inChan is closed")
}
return
}
func (stream *Stream) readInChanMsg() (data []byte, err error) {
select {
case data = <-stream.inChan:
case <-stream.closeChan:
err = errors.New("connection by inChan is closed")
}
return
}
func (stream *Stream) writeOutChan(dataMap map[string]interface{}) (err error) {
var (
data []byte
)
if data, err = json.Marshal(dataMap); err != nil {
return
}
select {
case stream.outChan <- data:
}
return
}
func (stream *Stream) ReadMsg() (resp *serverPb.SendAudioResponse, err error) {
if !stream.isCloseOutChan {
var (
data []byte
dataMap map[string]interface{}
)
select {
case data = <-stream.outChan:
}
if len(data) > 0 {
if err = json.Unmarshal(data, &dataMap); err != nil {
return
}
if dataMap["is_final"].(float64) == 1 {
resp = &serverPb.SendAudioResponse{
Code: 200,
IsResult: true,
IsFinal: true,
SessionId: stream.sessionId,
Results: dataMap["results"].(string),
SpeechDuration: int32(dataMap["duration"].(float64)),
DataIndex: stream.dataIndex,
//JsonData: fmt.Sprintf(`{"id":"%v","session_id":"%v","meeting_id":"%v"}`, dataMap["id"].(string), stream.sessionId, stream.meetingId),
}
if initServer.ConfigMap["mysqlUse"].(bool) {
resp.JsonData = fmt.Sprintf(`{"id":"%v","session_id":"%v","meeting_id":"%v"}`, dataMap["id"].(string), stream.sessionId, stream.meetingId)
}
}
if dataMap["is_final"].(float64) == 0 {
resp = &serverPb.SendAudioResponse{
Code: 200,
IsResult: true,
IsFinal: false,
SessionId: stream.sessionId,
Results: dataMap["results"].(string),
SpeechDuration: int32(dataMap["duration"].(float64)),
DataIndex: stream.dataIndex,
}
}
if dataMap["is_final"].(float64) == 3 {
resp = &serverPb.SendAudioResponse{
Code: 200,
IsResult: false,
IsFinal: false,
SessionId: stream.sessionId,
Results: "",
Description: dataMap["desc"].(string),
SpeechDuration: 0,
DataIndex: stream.dataIndex,
}
err = errors.New(dataMap["desc"].(string))
}
stream.dataIndex++
}
} else {
err = errors.New("outChan is closed")
}
return
}
func (stream *Stream) inChan2EngineLoop() {
var (
recData []byte
err error
)
for {
if recData, err = stream.readInChanMsg(); err != nil {
goto ERR
}
if string(recData) == `{"signal" : "end"}` {
stream.isEnd = true
if err = stream.engine.WriteMsg(recData, 1); err != nil {
goto ERR
}
} else if string(recData) == `{"signal" : "stop"}` {
if err = stream.engine.WriteMsg(recData, 2); err != nil {
goto ERR
}
} else {
//for i := 0; i < len(recData); i++ {
// recData[i] = recData[i] / 2
//}
if err = stream.engine.WriteMsg(recData, 0); err != nil {
goto ERR
}
go func(data []byte) {
if !stream.isTime {
stream.isTime = true
stream.startTime = time.Now()
}
stream.audioBuff.Write(data)
}(recData)
go func(data []byte) {
_, _ = stream.wave.SaveData(data)
}(recData)
}
}
ERR:
}
func (stream *Stream) Engine2OutChanLoop() {
var (
recData map[string]interface{}
err error
preResult string
preLength int
audioIndex = 1
duration float64
backup = make(map[string]interface{})
PostUrlHK = initServer.ConfigMap["postURL-ZH-HK"].(string)
PostUrlCN = initServer.ConfigMap["postURL-ZH-CN"].(string)
//regT, _ = regexp.Compile("[^\u4e00-\u9fa5a-zA-Z0-9]")
)
for {
if recData, err = stream.engine.ReadMsg(); err != nil {
goto ERR
}
if _, ok := recData["is_final"]; !ok {
logrus.Errorln(recData)
continue
}
if recData["is_final"].(float64) == 1 {
if stream.language == "ZH-CN" {
//if recData["results"].(string) != "" {
// if recData["results"], preResult, err = otherHandler.ChineseHandler(recData["results"].(string), preResult, initServer.ConfigMap["digitConvertURL-ZH-CN"].(string), initServer.ConfigMap["punctuationURL-ZH-CN"].(string), initServer.ConfigMap["sensitiveWordURL-ZH-CN"].(string), stream.punctuation, stream.sensitive, stream.digit); err != nil {
// }
//}
if recData["results"].(string) != "" {
reqBody := otherHandler.PostReq{}
reqBody.Texts = recData["results"].(string)
reqBody.Mode = 1
reqBody.Backup = backup
if resp, e := otherHandler.PostGet(reqBody, PostUrlCN); e != nil {
backup = make(map[string]interface{})
} else {
if resp != nil {
if resp.Status == 200 {
backup = resp.Backup
recData["results"] = resp.Result
} else {
backup = make(map[string]interface{})
}
} else {
backup = make(map[string]interface{})
}
}
}
}
if stream.language == "ZH-HK" {
//if recData["results"].(string) != "" {
// if recData["results"], preResult, err = otherHandler.CantoneseHandler(recData["results"].(string), preResult, initServer.ConfigMap["digitConvertURL-ZH-HK"].(string), initServer.ConfigMap["punctuationURL-ZH-HK"].(string), initServer.ConfigMap["sensitiveWordURL-ZH-HK"].(string), stream.punctuation, stream.sensitive, stream.digit); err != nil {
// }
//}
if recData["results"].(string) != "" {
reqBody := otherHandler.PostReq{}
reqBody.Texts = recData["results"].(string)
reqBody.Mode = 1
reqBody.Backup = backup
if resp, e := otherHandler.PostGet(reqBody, PostUrlHK); e != nil {
backup = make(map[string]interface{})
} else {
if resp != nil {
if resp.Status == 200 {
backup = resp.Backup
recData["results"] = resp.Result
} else {
backup = make(map[string]interface{})
}
} else {
backup = make(map[string]interface{})
}
}
}
}
if stream.language == "EN" {
if recData["results"].(string) != "" {
if recData["results"], preResult, preLength, err = otherHandler.EnglishHandler(recData["results"].(string), preResult, initServer.ConfigMap["EnPunctuationURL"].(string), initServer.ConfigMap["e2nURL"].(string), preLength, stream.punctuation, stream.digit); err != nil {
}
}
}
if initServer.ConfigMap["mysqlUse"].(bool) {
ids, _ := initServer.Snow.GetIds(1)
recData["id"] = ids[0]
}
duration, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", (recData["end"].(float64)-recData["start"].(float64))/float64(1000)), 64)
if recData["results"].(string) != "" {
go func(data map[string]interface{}, len float64) {
audioLength := int(data["duration"].(float64))
if audioLength != 0 {
var audio []byte
if stream.audioBuff.Len() >= audioLength {
audio = stream.audioBuff.Next(audioLength)
} else {
audio = stream.audioBuff.Bytes()
}
var (
sFile string
e error
)
if sFile, e = otherHandler.SaveAudioData(stream.meetingId, stream.sessionId, initServer.ConfigMap["audioPath"].(string), audio, audioIndex); e != nil {
initServer.Log.Log.WithFields(logrus.Fields{"source": "saving audio data error"}).Error(err.Error())
} else {
if initServer.ConfigMap["mysqlUse"].(bool) {
logData := otherHandler.LogData{
Id: recData["id"].(string),
User: stream.user,
SysType: stream.sysType,
MeetingId: stream.meetingId,
SessionId: stream.sessionId,
Texts: data["results"].(string),
AudioFile: sFile,
StartedAt: stream.startTime.Add(time.Duration(data["start"].(float64)) * time.Millisecond).Format("2006:01:02 15:04:05"),
CreatedAt: time.Now().Format("2006:01:02 15:04:05"),
UpdatedAt: time.Now().Format("2006:01:02 15:04:05"),
}
go func(logD otherHandler.LogData) {
getLogData := logD
initServer.LogData.SetData(getLogData)
}(logData)
}
audioIndex++
if stream.rDb != nil {
timestamp, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", float64(time.Now().UnixMilli())/float64(1000)), 64)
var pcmTime float64
pcmTime = data["end"].(float64) - data["start"].(float64)
pcmTime, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", pcmTime/float64(1000)), 64)
rdbStr := fmt.Sprintf(`{"timestamp":%v,"duration":%v,"url":"%v","raw_text":"%v","end_of_speech":%v,"pcmtime":%v,"meeting_id":"%v","session_id":"%v","entire_file_path":"%v","speaker":"%v","end":%v}`, timestamp, duration, sFile, data["results"].(string), 1, pcmTime, stream.meetingId, stream.sessionId, stream.wave.EFile, stream.speaker, 0)
_ = stream.rDb.PubMsg(rdbStr)
}
}
}
}(recData, duration)
} else {
if stream.audioBuff.Len() >= int(recData["duration"].(float64)) {
_ = stream.audioBuff.Next(int(recData["duration"].(float64)))
} else {
_ = stream.audioBuff.Bytes()
}
}
}
if recData["is_final"].(float64) == 3 {
goto ERR
}
if len(recData) > 0 {
if err = stream.writeOutChan(recData); err != nil {
goto ERR
}
}
}
ERR:
audio := stream.audioBuff.Bytes()
audioEndLen, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", float64(len(audio))/float64(1000)), 64)
duration = duration + audioEndLen
if sFile, e := otherHandler.SaveAudioData(stream.meetingId, stream.sessionId, initServer.ConfigMap["audioPath"].(string), audio, audioIndex); e != nil {
initServer.Log.Log.WithFields(logrus.Fields{"source": "saving audio data error"}).Error(err.Error())
} else {
if stream.rDb != nil {
timestamp, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", float64(time.Now().UnixMilli())/float64(1000)), 64)
var pcmTime float64
pcmTime, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", float64(len(audio))/float64(1000)), 64)
rdbStr := fmt.Sprintf(`{"timestamp":%v,"duration":%v,"url":"%v","raw_text":"%v","end_of_speech":%v,"pcmtime":%v,"meeting_id":"%v","session_id":"%v","entire_file_path":"%v","speaker":"%v","end":%v}`, timestamp, duration, sFile, "", 1, pcmTime, stream.meetingId, stream.sessionId, stream.wave.EFile, stream.speaker, 1)
_ = stream.rDb.PubMsg(rdbStr)
if initServer.ConfigMap["mysqlUse"].(bool) {
logData := otherHandler.LogData{
Id: "",
User: stream.user,
SysType: stream.sysType,
MeetingId: stream.meetingId,
SessionId: stream.sessionId,
Texts: "",
AudioFile: sFile,
StartedAt: time.Now().Format("2006:01:02 15:04:05"),
CreatedAt: time.Now().Format("2006:01:02 15:04:05"),
UpdatedAt: time.Now().Format("2006:01:02 15:04:05"),
End: true,
}
go func(logD otherHandler.LogData) {
getLogData := logD
e1 := initServer.LogData.SetData(getLogData)
if e1 != nil {
logrus.Errorln(e1)
_ = initServer.LogData.SetData(getLogData)
}
}(logData)
}
rdbEnd := fmt.Sprintf(`{"meeting_id":"%v","file_path":"%v","speaker":"%v"}`, stream.meetingId, stream.wave.EFile, false)
_ = stream.rDb.LeftPubMsg(rdbEnd)
stream.rDb.RedisClose()
}
_ = stream.wave.CloseWav()
}
}
//2023/04/07 17:46:54 {"id":"","texts":"三十七点八度分号血压二百到二百二十一六十至七十八毫米汞柱遵医嘱予丙泊酚调节冒号六点零毫升每小时","mode":1,"backup":{"command_flag":0,"pre_punc_result":"患者体温"}}
package serverHandler
import (
"fmt"
serverPb "gRPC-Raisound-Base-second-pass/Raisound-protobuf"
"gRPC-Raisound-Base-second-pass/initServer"
"github.com/sirupsen/logrus"
"time"
)
func (server *Service) StreamingASR(req serverPb.RaisoundSpeech_StreamingASRServer) (err error) {
var (
stream *Stream
isFirst bool
isClose bool
reqData *serverPb.SendAudioConfig
errMsg error
connInfoData map[string]interface{}
)
go func() {
var (
respData *serverPb.SendAudioResponse
e error
)
for {
if !isClose {
if stream != nil {
if respData, e = stream.ReadMsg(); e != nil {
goto ERR
}
go func(data *serverPb.SendAudioResponse) {
sendStr := fmt.Sprintf(`{"session_id":"%v","meeting_id":"%v","is_final":%v,"result":"%v"}`, stream.sessionId, stream.meetingId, data.IsFinal, data.Results)
initServer.Log.Log.WithFields(logrus.Fields{"source": "data sent to client"}).Info(sendStr)
}(respData)
if e = req.Send(respData); e != nil {
goto ERR
}
} else {
time.Sleep(500 * time.Millisecond)
}
} else {
time.Sleep(500 * time.Millisecond)
}
}
ERR:
if stream != nil {
stream.CloseChan()
}
}()
for {
if reqData, errMsg = req.Recv(); errMsg != nil {
goto ERR
}
if !isFirst {
if connInfoData, err = server.checkInfo(reqData.GetSessionId()); err != nil {
initServer.Log.Log.WithFields(logrus.Fields{"source": "check data from connection error"}).Error(err.Error())
goto ERR
}
if stream, err = InitStream(connInfoData); err != nil {
initServer.Log.Log.WithFields(logrus.Fields{"source": "nit stream error"}).Error(err.Error())
goto ERR
}
isFirst = true
}
if stream != nil {
if reqData.EndFlag == 1 {
if errMsg = stream.WriteMsg([]byte(`{"signal" : "stop"}`)); errMsg != nil {
goto ERR
}
continue
}
if errMsg = stream.WriteMsg(reqData.GetAudioData()); errMsg != nil {
goto ERR
}
}
}
ERR:
if stream != nil {
sendData := []byte(`{"signal" : "end"}`)
_ = stream.WriteMsg(sendData)
time.Sleep(500 * time.Millisecond)
stream.CloseChan()
}
time.Sleep(500 * time.Millisecond)
isClose = true
return
}
package serverHandler
import (
"errors"
serverPb "gRPC-Raisound-Base-second-pass/Raisound-protobuf"
"sync"
"time"
)
type Service struct {
serverPb.UnimplementedRaisoundSpeechServer
ConnInfo map[string]map[string]interface{}
lock sync.Mutex
}
func InitServer() (server *Service, err error) {
server = &Service{
ConnInfo: make(map[string]map[string]interface{}),
}
go server.checkAlive()
return
}
func (server *Service) Add(key string, value map[string]interface{}) (err error) {
server.lock.Lock()
if _, ok := server.ConnInfo[key]; !ok {
server.ConnInfo[key] = value
}
server.lock.Unlock()
return
}
func (server *Service) delete(key string) (err error) {
server.lock.Lock()
if _, ok := server.ConnInfo[key]; ok {
delete(server.ConnInfo, key)
}
server.lock.Unlock()
return
}
func (server *Service) checkInfo(key string) (value map[string]interface{}, err error) {
server.lock.Lock()
if firstData, ok1 := server.ConnInfo[key]; ok1 {
value = firstData
} else {
err = errors.New("session_id is error")
}
server.lock.Unlock()
return
}
func (server *Service) check(firstKey, secondKey string) (value interface{}, err error) {
server.lock.Lock()
if firstData, ok1 := server.ConnInfo[firstKey]; ok1 {
if getValue, ok2 := firstData[secondKey]; ok2 {
value = getValue
} else {
err = errors.New(secondKey + " is error")
}
} else {
err = errors.New("session_id is error")
}
server.lock.Unlock()
return
}
func (server *Service) checkSessionId(sessionId string) (isOk bool) {
server.lock.Lock()
_, isOk = server.ConnInfo[sessionId]
server.lock.Unlock()
return
}
func (server *Service) checkAlive() {
group := sync.WaitGroup{}
for {
server.lock.Lock()
for k, v := range server.ConnInfo {
key := k
value := v
group.Add(1)
go func() {
if value["time"].(int64)+12*60*60 <= time.Now().Unix() {
if _, ok := server.ConnInfo[key]; ok {
delete(server.ConnInfo, key)
}
}
group.Done()
}()
}
group.Wait()
server.lock.Unlock()
time.Sleep(5 * time.Minute)
}
}
#### 说明
#### 说明
- 该程序的主要主要接口是实时语音转文字的`gRPC`接口,主要使用的类型是双流式。
- 辅助接口有相应会议音频查询与下载的`http`接口。
- 这些接口共用同一个端口。
#### 实时语音转文字`gRPC`接口
- `。proto`文档
```
syntax = "proto3";
option go_package = "./Raisound-protobuf;raisound";
// 初始化语音流的设置
message InitConfig {
string token = 1;
string devid = 2;
string codec = 3;
int32 sample_rate = 4;
int32 sample_bits = 5;
int32 bitrate = 6;
string scene = 7;
string lang = 8;
int32 nbest = 9;
int32 vad_level = 10;
int32 max_speech_duration = 11;
string meeting_id = 12;
string app_name = 13;
string conn_id = 14;
bool oral_flag = 15;
bool sensitive_flag = 16;
bool punc_flag = 17;
bool num_convert_flag = 18;
string user = 19;
string passwd = 20;
int32 inter_outer_flag = 21; //除1外其他表示对内,1表示对外
}
// 初始化语音流的返回
message InitResponse {
int32 code = 1;
string session_id = 2;
string description = 3;
}
// 发送语音流数据的设置
message SendAudioConfig {
string session_id = 1;
bytes audio_data = 2;
int32 end_flag = 3;
int32 data_count = 4;
}
// 发送语音流的返回
message SendAudioResponse {
int32 code = 1;
bool is_result = 2;
bool is_final = 3;
string session_id = 4;
string results = 5;
string description = 6;
string json_data = 7;
int32 speech_duration = 8;
int32 data_index = 9;
}
// 发送心跳的设置
message HeartBeatConfig {
string session_id = 1;
}
// 发送心跳的返回
message HeartBeatResponse {
int32 code = 1;
string session_id = 2;
string description = 3;
}
// 释放语音流的设置
message RelConfig {
string session_id = 1;
}
// 释放语音流的返回
message RelResponse {
int32 code = 1;
string session_id = 2;
string description = 3;
}
service RaisoundSpeech {
rpc InitStreamingASR(InitConfig) returns(InitResponse);
rpc StreamingASR(stream SendAudioConfig) returns(stream SendAudioResponse);
rpc RelStreamingASR(RelConfig) returns(RelResponse);
rpc HeartBeat(HeartBeatConfig) returns(HeartBeatResponse);
}
```
> 1. 调用顺序 `InitStreamingASR` -> `StreamingASR` -> `RelStreamingASR`。
> 2. `HeartBeat` 新版中不需要使用到了。
> 3. `InitStreamingASR`:当`inter_outer_flag`不等于`1`时,`user`默认为`admin`,`passwd`默认为`123456`,只要这三个即可登录获取`session_id`;当`inter_outer_flag`等于`1`时,需要获取`token`,之后也可以登录获取取`session_id`。`meeting_id`即为会议`ID`,可无,若传值时,后端保存音频或发布`redis`时会以这的`ID`为主要标识,否者后端会以接入的当前时刻为会议`ID`.
> 4. `StreamingASR`:请求的`session_id`是在`InitStreamingASR`步骤获取的,之后流式中每一帧数据都要以这个`session_id`为标识。其中`data_count`在新版中已经不再调用。`end_flag`是紧急将临时结果变成最终结果,特殊场景调用。
- 调用过程
- `InitStreamingASR`初始化
- 请求结构`InitConfig`(现用使用到的参数)
| 参数 | 要求 | 说明 |
| :---: | :---: | :--- |
| `token` | 字符串 | 通过接口获取,当`inter_outer_flag`为`1`是必要。 |
| `user`|字符串|当`inter_outer_flag`为`1`是必要,默认`admin`|
|`passwd` |字符串|当`inter_outer_flag`为`1`是必要,默认`123456`|
|`meeting_id`|字符串|没有传这个参数,后端以接入时刻为其值,非必要|
|`inter_outer_flag`|整数|为`1`事和token组成即可获取`session_id`;其他值时和`user`/`passwd`组成也可获取`session_id`。其值默认为`1`|
- 响应结构`InitResponse`
| 参数 | 要求 | 说明 |
| :---: | :---: | :--- |
|`code`| 整数 |`200`成功|
|`session_id`|字符串|整个会议过程都会以这个`session_id`为基础|
|`description`|字符串|说用描述|
- `StreamingASR`识别(双流式)
- 请求结构`SendAudioConfig`
| 参数 | 要求 | 说明 |
| :---: | :---: | :--- |
|`session_id`|字符串|`InitStreamingASR`获取的`session_id`|
|`audio_data`|音频数据|音频采样频率为`16000`,单声道,每一帧大小建议`1600`~`3200`|
|`end_flag`|字符串|紧急将临时结果变成最终结果,特殊场景调用|
|`data_count`|整数|非必要,新版没有调用到|
- 响应结构`SendAudioResponse`
| 参数 | 要求 | 说明 |
| :---: | :---: | :--- |
|`code`|整数|`200`成功|
|`is_result`|布尔类型|`True`未有结果,`False`为没有结果|
|`is_final`|布尔类型|`True`最终结果,`False`为临时结果|
|`session_id`|字符串|`SendAudioConfig`的`session_id`|
|`results`|字符串|音频文字结果|
|`description`|字符串|详情描述|
|`json_data`|字符串|`json`格式的结果,目前没使用这个参数,非必要|
|`speech_duration`|整数|非必要|
|`data_index`|整数|非必要|
- `RelStreamingASR`释放
- 请求结构`RelConfig`
| 参数 | 要求 | 说明 |
| :---: | :---: | :--- |
|`session_id`|字符串|`InitStreamingASR`获取的`session_id`|
- 响应结构`RelResponse`
| 参数 | 要求 | 说明 |
| :---: | :---: | :--- |
|`code`|整数|`200`成功|
|`session_id`|字符串|`RelConfig`的`session_id`|
|`description`|字符串|详情描述|
> 在释放段阶段,客户端要断开`gRPC`的连接
#### 查询会议音频`http`接口(`GET`)
- 基本请求结构
- `header`头结构
```
{"token":{token值}}
```
- 请求链接(假如服务端口是`20065`)
```
http://127.0.0.1:20065/getAudioFile?meeting_id={meeting_id值}
```
- 响应结构
- 成功
```
{
"code":200,
"data":{下载音频链接},
"description":"succeed"
}
```
- 失败
- 没带`header`头
```
{
"code":400,
"description":"token is empty."
}
```
- 没传`meeting_id`值
```
{
"code":400,
"description":"The parameter value is missing."
}
```
- 音频文件不存在
```
{
"code":404,
"description":"The file does not exist."
}
```
- `token`值不正确
```
{
"code":401,
"description":"token error."
}
```
- 其他错误
```
{
"code":404,
"description":{错误描述}
}
```
#### 下载会议音频`http`接口(`GET`)
> 说明:下载接口是根据查询接口正确返回拿到的
- 错误响应说明
- 错误一
```
{
"code":404,
"description":"file path error."
}
```
- 错误二
```
{
"code":403,
"description":"The address is invalid"
}
```
- 错误三
```
{
"code":400,
"description":{错误描述}
}
```
#### 会议结束音频异常后调`http`接口(`GET`)
- 请求链接(假如服务端口是`20065`)
```
http://127.0.0.1:20065/getEnd/{meeting_id值}
```
- 响应结构
- 成功
```
{
"code":200,
"description":"succeed",
"meeting_id":{meetingId的值}
}
```
- 会议不存在
```
{
"code":403,
"description":"can find the meeting"
}
```
- `meeting_id`值为空
```
{
"code":400,
"description":"the meeting_id is empty,please check the value of meeting_id."
}
```
- 其他错误
```
{
"code":404,
"description":{错误描述}
}
```
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment