Merge pull request #2011 from mozilla/free-strings
Provide an API function to free strings returned by API (Fixes #1979)
This commit is contained in:
commit
0b4b806cbf
@ -246,7 +246,7 @@ ProcessFile(ModelState* context, const char* path, bool show_times)
|
|||||||
|
|
||||||
if (result.string) {
|
if (result.string) {
|
||||||
printf("%s\n", result.string);
|
printf("%s\n", result.string);
|
||||||
free((void*)result.string);
|
DS_FreeString((char*)result.string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_times) {
|
if (show_times) {
|
||||||
|
@ -926,6 +926,12 @@ DS_FreeMetadata(Metadata* m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DS_FreeString(char* str)
|
||||||
|
{
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DS_PrintVersions() {
|
DS_PrintVersions() {
|
||||||
std::cerr << "TensorFlow: " << tf_local_git_version() << std::endl;
|
std::cerr << "TensorFlow: " << tf_local_git_version() << std::endl;
|
||||||
|
@ -116,8 +116,8 @@ int DS_EnableDecoderWithLM(ModelState* aCtx,
|
|||||||
* @param aBufferSize The number of samples in the audio signal.
|
* @param aBufferSize The number of samples in the audio signal.
|
||||||
* @param aSampleRate The sample-rate of the audio signal.
|
* @param aSampleRate The sample-rate of the audio signal.
|
||||||
*
|
*
|
||||||
* @return The STT result. The user is responsible for freeing the string.
|
* @return The STT result. The user is responsible for freeing the string using
|
||||||
* Returns NULL on error.
|
* {@link DS_FreeString()}. Returns NULL on error.
|
||||||
*/
|
*/
|
||||||
DEEPSPEECH_EXPORT
|
DEEPSPEECH_EXPORT
|
||||||
char* DS_SpeechToText(ModelState* aCtx,
|
char* DS_SpeechToText(ModelState* aCtx,
|
||||||
@ -187,7 +187,7 @@ void DS_FeedAudioContent(StreamingState* aSctx,
|
|||||||
* @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}.
|
* @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}.
|
||||||
*
|
*
|
||||||
* @return The STT intermediate result. The user is responsible for freeing the
|
* @return The STT intermediate result. The user is responsible for freeing the
|
||||||
* string.
|
* string using {@link DS_FreeString()}.
|
||||||
*/
|
*/
|
||||||
DEEPSPEECH_EXPORT
|
DEEPSPEECH_EXPORT
|
||||||
char* DS_IntermediateDecode(StreamingState* aSctx);
|
char* DS_IntermediateDecode(StreamingState* aSctx);
|
||||||
@ -198,7 +198,8 @@ char* DS_IntermediateDecode(StreamingState* aSctx);
|
|||||||
*
|
*
|
||||||
* @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}.
|
* @param aSctx A streaming state pointer returned by {@link DS_SetupStream()}.
|
||||||
*
|
*
|
||||||
* @return The STT result. The user is responsible for freeing the string.
|
* @return The STT result. The user is responsible for freeing the string using
|
||||||
|
* {@link DS_FreeString()}.
|
||||||
*
|
*
|
||||||
* @note This method will free the state pointer (@p aSctx).
|
* @note This method will free the state pointer (@p aSctx).
|
||||||
*/
|
*/
|
||||||
@ -237,6 +238,12 @@ void DS_DiscardStream(StreamingState* aSctx);
|
|||||||
DEEPSPEECH_EXPORT
|
DEEPSPEECH_EXPORT
|
||||||
void DS_FreeMetadata(Metadata* m);
|
void DS_FreeMetadata(Metadata* m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Free a char* string returned by the DeepSpeech API.
|
||||||
|
*/
|
||||||
|
DEEPSPEECH_EXPORT
|
||||||
|
void DS_FreeString(char* str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Print version of this library and of the linked TensorFlow library.
|
* @brief Print version of this library and of the linked TensorFlow library.
|
||||||
*/
|
*/
|
||||||
|
@ -15,6 +15,11 @@
|
|||||||
%pointer_functions(ModelState*, modelstatep);
|
%pointer_functions(ModelState*, modelstatep);
|
||||||
%pointer_functions(StreamingState*, streamingstatep);
|
%pointer_functions(StreamingState*, streamingstatep);
|
||||||
|
|
||||||
|
%typemap(newfree) char* "DS_FreeString($1);";
|
||||||
|
%newobject DS_SpeechToText;
|
||||||
|
%newobject DS_IntermediateDecode;
|
||||||
|
%newobject DS_FinishStream;
|
||||||
|
|
||||||
%rename ("%(strip:[DS_])s") "";
|
%rename ("%(strip:[DS_])s") "";
|
||||||
|
|
||||||
%include "../deepspeech.h"
|
%include "../deepspeech.h"
|
||||||
|
@ -27,7 +27,7 @@ using namespace node;
|
|||||||
|
|
||||||
|
|
||||||
// make sure the string returned by SpeechToText is freed
|
// make sure the string returned by SpeechToText is freed
|
||||||
%typemap(newfree) char* "free($1);";
|
%typemap(newfree) char* "DS_FreeString($1);";
|
||||||
%newobject DS_SpeechToText;
|
%newobject DS_SpeechToText;
|
||||||
%newobject DS_IntermediateDecode;
|
%newobject DS_IntermediateDecode;
|
||||||
%newobject DS_FinishStream;
|
%newobject DS_FinishStream;
|
||||||
|
@ -33,7 +33,7 @@ import_array();
|
|||||||
%append_output(SWIG_NewPointerObj(%as_voidptr(*$1), $*1_descriptor, 0));
|
%append_output(SWIG_NewPointerObj(%as_voidptr(*$1), $*1_descriptor, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(newfree) char* "free($1);";
|
%typemap(newfree) char* "DS_FreeString($1);";
|
||||||
%newobject DS_SpeechToText;
|
%newobject DS_SpeechToText;
|
||||||
%newobject DS_IntermediateDecode;
|
%newobject DS_IntermediateDecode;
|
||||||
%newobject DS_FinishStream;
|
%newobject DS_FinishStream;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user