Wav to Base64 converter in CFD

Status
Not open for further replies.

idkhtn

Free User
Joined
Nov 15, 2023
Messages
5
Reaction score
1
Hello,

In my CFD app I'm trying to write a custom c# script Base64 converter in order to convert wav output from Record component (Record1.AudioId) to a base64 string (put to variable OutputText) that could be later embedded in JSON request. What is the correct approach here?

Any help appreciated!
 

Attachments

  • 2023-11-29 12_51_15-Execute C# Code.png
    2023-11-29 12_51_15-Execute C# Code.png
    78.1 KB · Views: 8
  • 2023-11-29 12_51_45-3CX Call Flow Designer - Voicebot_fur_die_Telefonzentrale_rest working_1.png
    2023-11-29 12_51_45-3CX Call Flow Designer - Voicebot_fur_die_Telefonzentrale_rest working_1.png
    32.4 KB · Views: 7
The AudioId is the file path. So you will need to read the file contents, encode it as you need, and return the encoded text.
 
  • Like
Reactions: Evolute IT
Thank you for quick answer:) My solution so far consists of:

My input parameters:
AudioId String Record1.AudioId


1.reading the contents of the audio file and assigning it to "bytes" Variable (should I also add "bytes" to input parameters? )

byte[] bytes = File.ReadAllBytes(AudioId);

2.encoding using ToBase64String
string base64 = Convert.ToBase64String(bytes);

3.assigning the returned value to OutputText using assign variable component (should I do it inside the script?)

im also getting an error that not all code paths return value

:[33168..33192)E: (627,27)-(627,51): Error CS0161: "Main.ExecuteCSharpCode11743652179ECCComponent.ConvertWavToBase64String(string)": Nicht alle Codepfade geben einen Wert zurück. private object ConvertWavToBase64String(string AudioId)
^^^^^^^^^^^^^^^^^^^^^^^^
 
byte[] bytes = File.ReadAllBytes(AudioId);
string base64 = Convert.ToBase64String(bytes);
return base64;

Now the error seems to be resolved
 
  • Like
Reactions: edossantos
Status
Not open for further replies.