Committed by
GitHub
[update] fixed bug: create golang instance succeed while the c struct create failed (#1860)
正在显示
1 个修改的文件
包含
45 行增加
和
16 行删除
| @@ -239,9 +239,12 @@ func NewOnlineRecognizer(config *OnlineRecognizerConfig) *OnlineRecognizer { | @@ -239,9 +239,12 @@ func NewOnlineRecognizer(config *OnlineRecognizerConfig) *OnlineRecognizer { | ||
| 239 | defer C.free(unsafe.Pointer(c.ctc_fst_decoder_config.graph)) | 239 | defer C.free(unsafe.Pointer(c.ctc_fst_decoder_config.graph)) |
| 240 | c.ctc_fst_decoder_config.max_active = C.int(config.CtcFstDecoderConfig.MaxActive) | 240 | c.ctc_fst_decoder_config.max_active = C.int(config.CtcFstDecoderConfig.MaxActive) |
| 241 | 241 | ||
| 242 | + impl := C.SherpaOnnxCreateOnlineRecognizer(&c) | ||
| 243 | + if impl == nil { | ||
| 244 | + return nil | ||
| 245 | + } | ||
| 242 | recognizer := &OnlineRecognizer{} | 246 | recognizer := &OnlineRecognizer{} |
| 243 | - recognizer.impl = C.SherpaOnnxCreateOnlineRecognizer(&c) | ||
| 244 | - | 247 | + recognizer.impl = impl |
| 245 | return recognizer | 248 | return recognizer |
| 246 | } | 249 | } |
| 247 | 250 | ||
| @@ -580,8 +583,12 @@ func NewOfflineRecognizer(config *OfflineRecognizerConfig) *OfflineRecognizer { | @@ -580,8 +583,12 @@ func NewOfflineRecognizer(config *OfflineRecognizerConfig) *OfflineRecognizer { | ||
| 580 | c.rule_fars = C.CString(config.RuleFars) | 583 | c.rule_fars = C.CString(config.RuleFars) |
| 581 | defer C.free(unsafe.Pointer(c.rule_fars)) | 584 | defer C.free(unsafe.Pointer(c.rule_fars)) |
| 582 | 585 | ||
| 586 | + impl := C.SherpaOnnxCreateOfflineRecognizer(&c) | ||
| 587 | + if impl == nil { | ||
| 588 | + return nil | ||
| 589 | + } | ||
| 583 | recognizer := &OfflineRecognizer{} | 590 | recognizer := &OfflineRecognizer{} |
| 584 | - recognizer.impl = C.SherpaOnnxCreateOfflineRecognizer(&c) | 591 | + recognizer.impl = impl |
| 585 | 592 | ||
| 586 | return recognizer | 593 | return recognizer |
| 587 | } | 594 | } |
| @@ -816,9 +823,12 @@ func NewOfflineTts(config *OfflineTtsConfig) *OfflineTts { | @@ -816,9 +823,12 @@ func NewOfflineTts(config *OfflineTtsConfig) *OfflineTts { | ||
| 816 | c.model.provider = C.CString(config.Model.Provider) | 823 | c.model.provider = C.CString(config.Model.Provider) |
| 817 | defer C.free(unsafe.Pointer(c.model.provider)) | 824 | defer C.free(unsafe.Pointer(c.model.provider)) |
| 818 | 825 | ||
| 826 | + impl := C.SherpaOnnxCreateOfflineTts(&c) | ||
| 827 | + if impl == nil { | ||
| 828 | + return nil | ||
| 829 | + } | ||
| 819 | tts := &OfflineTts{} | 830 | tts := &OfflineTts{} |
| 820 | - tts.impl = C.SherpaOnnxCreateOfflineTts(&c) | ||
| 821 | - | 831 | + tts.impl = impl |
| 822 | return tts | 832 | return tts |
| 823 | } | 833 | } |
| 824 | 834 | ||
| @@ -951,9 +961,12 @@ func NewVoiceActivityDetector(config *VadModelConfig, bufferSizeInSeconds float3 | @@ -951,9 +961,12 @@ func NewVoiceActivityDetector(config *VadModelConfig, bufferSizeInSeconds float3 | ||
| 951 | 961 | ||
| 952 | c.debug = C.int(config.Debug) | 962 | c.debug = C.int(config.Debug) |
| 953 | 963 | ||
| 964 | + impl := C.SherpaOnnxCreateVoiceActivityDetector(&c, C.float(bufferSizeInSeconds)) | ||
| 965 | + if impl == nil { | ||
| 966 | + return nil | ||
| 967 | + } | ||
| 954 | vad := &VoiceActivityDetector{} | 968 | vad := &VoiceActivityDetector{} |
| 955 | - vad.impl = C.SherpaOnnxCreateVoiceActivityDetector(&c, C.float(bufferSizeInSeconds)) | ||
| 956 | - | 969 | + vad.impl = impl |
| 957 | return vad | 970 | return vad |
| 958 | } | 971 | } |
| 959 | 972 | ||
| @@ -1107,9 +1120,12 @@ func NewSpeakerEmbeddingExtractor(config *SpeakerEmbeddingExtractorConfig) *Spea | @@ -1107,9 +1120,12 @@ func NewSpeakerEmbeddingExtractor(config *SpeakerEmbeddingExtractorConfig) *Spea | ||
| 1107 | c.provider = C.CString(config.Provider) | 1120 | c.provider = C.CString(config.Provider) |
| 1108 | defer C.free(unsafe.Pointer(c.provider)) | 1121 | defer C.free(unsafe.Pointer(c.provider)) |
| 1109 | 1122 | ||
| 1123 | + impl := C.SherpaOnnxCreateSpeakerEmbeddingExtractor(&c) | ||
| 1124 | + if impl == nil { | ||
| 1125 | + return nil | ||
| 1126 | + } | ||
| 1110 | ex := &SpeakerEmbeddingExtractor{} | 1127 | ex := &SpeakerEmbeddingExtractor{} |
| 1111 | - ex.impl = C.SherpaOnnxCreateSpeakerEmbeddingExtractor(&c) | ||
| 1112 | - | 1128 | + ex.impl = impl |
| 1113 | return ex | 1129 | return ex |
| 1114 | } | 1130 | } |
| 1115 | 1131 | ||
| @@ -1159,8 +1175,12 @@ type SpeakerEmbeddingManager struct { | @@ -1159,8 +1175,12 @@ type SpeakerEmbeddingManager struct { | ||
| 1159 | // The user has to invoke [DeleteSpeakerEmbeddingManager]() to free the returned | 1175 | // The user has to invoke [DeleteSpeakerEmbeddingManager]() to free the returned |
| 1160 | // value to avoid memory leak | 1176 | // value to avoid memory leak |
| 1161 | func NewSpeakerEmbeddingManager(dim int) *SpeakerEmbeddingManager { | 1177 | func NewSpeakerEmbeddingManager(dim int) *SpeakerEmbeddingManager { |
| 1178 | + impl := C.SherpaOnnxCreateSpeakerEmbeddingManager(C.int(dim)) | ||
| 1179 | + if impl == nil { | ||
| 1180 | + return nil | ||
| 1181 | + } | ||
| 1162 | m := &SpeakerEmbeddingManager{} | 1182 | m := &SpeakerEmbeddingManager{} |
| 1163 | - m.impl = C.SherpaOnnxCreateSpeakerEmbeddingManager(C.int(dim)) | 1183 | + m.impl = impl |
| 1164 | return m | 1184 | return m |
| 1165 | } | 1185 | } |
| 1166 | 1186 | ||
| @@ -1435,9 +1455,12 @@ func NewOfflinePunctuation(config *OfflinePunctuationConfig) *OfflinePunctuation | @@ -1435,9 +1455,12 @@ func NewOfflinePunctuation(config *OfflinePunctuationConfig) *OfflinePunctuation | ||
| 1435 | cfg.model.provider = C.CString(config.Model.Provider) | 1455 | cfg.model.provider = C.CString(config.Model.Provider) |
| 1436 | defer C.free(unsafe.Pointer(cfg.model.provider)) | 1456 | defer C.free(unsafe.Pointer(cfg.model.provider)) |
| 1437 | 1457 | ||
| 1458 | + impl := C.SherpaOnnxCreateOfflinePunctuation(&cfg) | ||
| 1459 | + if impl == nil { | ||
| 1460 | + return nil | ||
| 1461 | + } | ||
| 1438 | punc := &OfflinePunctuation{} | 1462 | punc := &OfflinePunctuation{} |
| 1439 | - punc.impl = C.SherpaOnnxCreateOfflinePunctuation(&cfg) | ||
| 1440 | - | 1463 | + punc.impl = impl |
| 1441 | return punc | 1464 | return punc |
| 1442 | } | 1465 | } |
| 1443 | 1466 | ||
| @@ -1544,9 +1567,12 @@ func NewKeywordSpotter(config *KeywordSpotterConfig) *KeywordSpotter { | @@ -1544,9 +1567,12 @@ func NewKeywordSpotter(config *KeywordSpotterConfig) *KeywordSpotter { | ||
| 1544 | 1567 | ||
| 1545 | c.keywords_buf_size = C.int(config.KeywordsBufSize) | 1568 | c.keywords_buf_size = C.int(config.KeywordsBufSize) |
| 1546 | 1569 | ||
| 1570 | + impl := C.SherpaOnnxCreateKeywordSpotter(&c) | ||
| 1571 | + if impl == nil { | ||
| 1572 | + return nil | ||
| 1573 | + } | ||
| 1547 | spotter := &KeywordSpotter{} | 1574 | spotter := &KeywordSpotter{} |
| 1548 | - spotter.impl = C.SherpaOnnxCreateKeywordSpotter(&c) | ||
| 1549 | - | 1575 | + spotter.impl = impl |
| 1550 | return spotter | 1576 | return spotter |
| 1551 | } | 1577 | } |
| 1552 | 1578 | ||
| @@ -1665,9 +1691,12 @@ func NewAudioTagging(config *AudioTaggingConfig) *AudioTagging { | @@ -1665,9 +1691,12 @@ func NewAudioTagging(config *AudioTaggingConfig) *AudioTagging { | ||
| 1665 | 1691 | ||
| 1666 | c.top_k = C.int(config.TopK) | 1692 | c.top_k = C.int(config.TopK) |
| 1667 | 1693 | ||
| 1694 | + impl := C.SherpaOnnxCreateAudioTagging(&c) | ||
| 1695 | + if impl == nil { | ||
| 1696 | + return nil | ||
| 1697 | + } | ||
| 1668 | tagging := &AudioTagging{} | 1698 | tagging := &AudioTagging{} |
| 1669 | - tagging.impl = C.SherpaOnnxCreateAudioTagging(&c) | ||
| 1670 | - | 1699 | + tagging.impl = impl |
| 1671 | return tagging | 1700 | return tagging |
| 1672 | } | 1701 | } |
| 1673 | 1702 |
-
请 注册 或 登录 后发表评论