Question / Help Special characters in texts read from file

Barthelomeus

New Member
I cannot manage to import special characters from a text file.
The textfile is in UTF-8. In my text editor I can see the correct character:
edit.jpg

Still after import, on the screen the character is replaced:
obs.jpg

The font I use is Calibri, but Arial gives me the same result.
To be honest, I don't know where to look for the answer...
Bart

 

Barthelomeus

New Member
I solved the problem myself:
The VB-program I used to connect RadioDJ to OBS studio didn't write in UTF-8.
But I found a way to make it use UTF-8 and now the system works fine.
Bart
 

Barthelomeus

New Member
To explain the solution I have to describe what I’m doing.
I have a radio station that I want to stream on Youtube.
For the audio I use RadioDJ and for the video OBS.
On the video I want to show the ‘now playing’ info, So I have to link the two programs. In principle, that’s straight forward: RadioDJ has the ability to write a file named NowPlaying.txt in which all the info can be put.
And OBS has a text-source that can read the file and show it.

The only problem: RadioDJ doesn’t write the text file in UTF-8. I couldn’t find what it does, but in OBS all special characters are replaced by question marks.

So I need an extra program that links the audio with the video. I’ve written a program in Visual Studio 12 (visual basic variant).

This is the code:
Code:
Dim a, a1, b, c, d, f As String
    Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated
        Me.Timer1.Enabled = True
        Me.Timer1.Interval = 1200
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        On Error GoTo badluck
        FileOpen(1, "c:\temp\NowPlaying.txt", OpenMode.Input)
        a = LineInput(1)
        b = LineInput(1)
        c = LineInput(1)
        d = LineInput(1)
        f = LineInput(1)
        FileClose(1)
        If a <> a1 Then
            a1 = a
            b = b + Chr(10) + c + Chr(10) + d + Chr(10) + f

            Dim fsT As Object
            fsT = CreateObject("ADODB.Stream")
            fsT.Type = 2 'Specify stream type - we want To save text/string data.
            fsT.Charset = "utf-8" 'Specify charset For the source text data.
            fsT.Open() 'Open the stream And write binary data To the object
            fsT.WriteText(b)
            fsT.SaveToFile("c:\temp\PlayingNow.txt", 2) 'Save binary data To disk

        End If

badluck:
    End Sub

And here is the breakdown:
Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated
Me.Timer1.Enabled = True
Me.Timer1.Interval = 1200
End Sub
I use a timer that restarts the scan routine every 1.2 seconds.

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
On Error GoTo badluck
FileOpen(1, "c:\temp\NowPlaying.txt", OpenMode.Input)
a = LineInput(1)
b = LineInput(1)
c = LineInput(1)
d = LineInput(1)
f = LineInput(1)
FileClose(1)
Because two programs use the same file, I have to cater for a clash between them.
The On Error GoTo ends the routine immediately. No problem, the program will retry in 1.2 seconds.
In the FileOpen part, I read the NowPlaying file and I put the information in the computer memory.
If a <> a1 Then
a1 = a
b = b + Chr(10) + c + Chr(10) + d + Chr(10) + f
I don't want to write new files when nothing has changed, so in a there is an identifier, and only when the identifier changes the next routine will be executed.
Then I prepare the text I want to display in OBS. I put it in b.
Dim fsT As Object
fsT = CreateObject("ADODB.Stream")
fsT.Type = 2 'Specify stream type - we want To save text/string data.
fsT.Charset = "utf-8" 'Specify charset For the source text data.
fsT.Open() 'Open the stream And write binary data To the object
fsT.WriteText(b)
fsT.SaveToFile("c:\temp\PlayingNow.txt", 2) 'Save binary data To disk
The next seven lines I got from a website somewhere. I don't know how it works, but it does...
The only changes I made: In the sixth line I added b with the content I want to display in OBS.
And in the last line I added the new file name. I use that file in OBS to show the info.

Thanks to line 4 the encoding is now in UTF-8.

I hope this is enough of an explanation to help everyone with the same problem.
I take questions, so use reply if you want to.

Bart
 

Barthelomeus

New Member
In RadioDJ there is a way to export UTF8 text.
You'll find it in the plugin Now Playing Info in the drop down item Text Encoding.
 

wfzacarias

New Member
Hello Bart. I tried to create the code in Visual Studio, but I couldn't. Couldn't you send the software you created via a link? It would help a lot.
 
Top