Ondertitel naar spraak

Pagina: 1
Acties:

Vraag


  • Richard1234
  • Registratie: September 2026
  • Laatst online: 19:18
Ik zet ondertitel om naar spraak.

Maar mij programma stopt er te voeg mee.

Weet iemand wat ik fout doe ?

Imports System

Imports System.Globalization

Imports System.Speech.Synthesis

Imports System.Threading

Imports System.Threading.Thread

Imports System.Speech.AudioFormat

Imports System.IO

Imports System.Media

Imports System.Text.RegularExpressions

Imports System.Text

Public Class Form1

Private Declare Function record Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer

Dim synth = New SpeechSynthesizer()

' define the TimeSpan format and culture

Private Const CustomTimeSpanFormat As String = "hh\:mm\:ss\,fff"

Private ReadOnly _culture As CultureInfo = CultureInfo.CurrentCulture

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

synth.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Adult, 2, CultureInfo.GetCultureInfo("nl-NL"))

End Sub

Private Async Sub ButtonStartDelay_Click(sender As Object, e As EventArgs) Handles ButtonStartDelay.Click

TextBoxInput.Enabled = False

ButtonStartDelay.Enabled = False

ButtonStartDelay.Text = "Busy..."

TextBoxOutput.Clear()

record("open new Type waveaudio Alias recsound", "", 0, 0)

record("record recsound", "", 0, 0)

' loop over each line in the input

Dim previousWaitTime As TimeSpan = TimeSpan.Zero

ProgressBar1.Maximum = 1

ProgressBar1.Value = 0

Dim o As Integer = 1

For Each line As String In TextBoxInput.Lines

' try to parse the TimeSpan using the custom format and culture

Dim currentWaitTime As TimeSpan

If (Not TimeSpan.TryParseExact(line, CustomTimeSpanFormat, _culture, currentWaitTime)) Then

AppendLine(TextBoxOutput, $"Invalid TimeSpan format: {line}")

TextBox1.Text = line

If line.Length >= 1 AndAlso line.Length <= 3 Then

TextBox1.Text = Regex.Replace(TextBox1.Lines(0), "[1-999]", "")

Else

synth.SpeakAsync(TextBox1.Text)

End If

Continue For

End If

' calculate the delay

Dim delay As TimeSpan = currentWaitTime - previousWaitTime

AppendLine(TextBoxOutput, $"Wait {delay.TotalSeconds:F3} seconds")

With Me.TextBoxOutput

.SelectionStart = Len(.Text)

.ScrollToCaret()

End With

With Me.TextBoxInput

.SelectionStart = Len(.Text)

.ScrollToCaret()

End With

If (delay > TimeSpan.Zero) Then

' only delay if there's actually time to wait

ProgressBar1.Maximum = delay.TotalSeconds()

TimerDelay.Start()

Await Task.Delay(delay)

End If

previousWaitTime = currentWaitTime

Next

record("save recsound e:\mic.wav", "", 0, 0)

record("close recsound", "", 0, 0)

TextBoxInput.Enabled = True

ButtonStartDelay.Enabled = True

ButtonStartDelay.Text = "Start Delay"

End Sub

Private Sub TimerDelay_Tick(sender As Object, e As EventArgs) Handles TimerDelay.Tick

If (ProgressBar1.Value = ProgressBar1.Maximum) Then

TimerDelay.Stop()

Else

ProgressBar1.Value += 1

End If

End Sub

Private Shared Sub AppendLine(destination As TextBox, line As String)

destination.Lines = destination.Lines.Concat({line}).ToArray()

End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

OpenFileDialog1.Title = "Please select a subtitle file"

OpenFileDialog1.FileName = ""

' OpenFileDialog1.InitialDirectory = "C:\"

OpenFileDialog1.Filter = "Subtitle Files|*.srt"

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim content As String = File.ReadAllText(OpenFileDialog1.FileName, Encoding.UTF8)

TextBoxInput.Text = content

End If

TextBoxInput.Lines = TextBoxInput.Lines.Where(Function(line) line <> String.Empty).ToArray()

Dim Term As String = " -->"

Dim lines() As String = TextBoxInput.Lines

For x As Integer = 0 To lines.GetUpperBound(0)

If lines(x).Contains(Term) Then

lines(x) = lines(x).Substring(0, lines(x).IndexOf(Term))

End If

Next

TextBoxInput.Lines = lines

End Sub

End Class

Alle reacties


  • Richard1234
  • Registratie: September 2026
  • Laatst online: 19:18
Imports System
Imports System.Globalization
Imports System.Speech.Synthesis
Imports System.Threading
Imports System.Threading.Thread
Imports System.Speech.AudioFormat
Imports System.IO
Imports System.Media
Imports System.Text.RegularExpressions
Imports System.Text


Public Class Form1
Private Declare Function record Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Dim synth = New SpeechSynthesizer()
' define the TimeSpan format and culture
Private Const CustomTimeSpanFormat As String = "hh\:mm\:ss\,fff"
Private ReadOnly _culture As CultureInfo = CultureInfo.CurrentCulture

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
synth.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Adult, 2, CultureInfo.GetCultureInfo("nl-NL"))
End Sub

Private Async Sub ButtonStartDelay_Click(sender As Object, e As EventArgs) Handles ButtonStartDelay.Click

TextBoxInput.Enabled = False
ButtonStartDelay.Enabled = False
ButtonStartDelay.Text = "Busy..."
TextBoxOutput.Clear()
record("open new Type waveaudio Alias recsound", "", 0, 0)
record("record recsound", "", 0, 0)
' loop over each line in the input
Dim previousWaitTime As TimeSpan = TimeSpan.Zero

ProgressBar1.Maximum = 1
ProgressBar1.Value = 0


Dim o As Integer = 1
For Each line As String In TextBoxInput.Lines


' try to parse the TimeSpan using the custom format and culture
Dim currentWaitTime As TimeSpan
If (Not TimeSpan.TryParseExact(line, CustomTimeSpanFormat, _culture, currentWaitTime)) Then

AppendLine(TextBoxOutput, $"Invalid TimeSpan format: {line}")

TextBox1.Text = line


If line.Length >= 1 AndAlso line.Length <= 3 Then
TextBox1.Text = Regex.Replace(TextBox1.Lines(0), "[1-999]", "")
Else
synth.SpeakAsync(TextBox1.Text)

End If
Continue For
End If

' calculate the delay
Dim delay As TimeSpan = currentWaitTime - previousWaitTime
AppendLine(TextBoxOutput, $"Wait {delay.TotalSeconds:F3} seconds")

With Me.TextBoxOutput
.SelectionStart = Len(.Text)
.ScrollToCaret()
End With

With Me.TextBoxInput
.SelectionStart = Len(.Text)
.ScrollToCaret()
End With

If (delay > TimeSpan.Zero) Then
' only delay if there's actually time to wait
ProgressBar1.Maximum = delay.TotalSeconds()
TimerDelay.Start()
Await Task.Delay(delay)

End If

previousWaitTime = currentWaitTime
Next
record("save recsound e:\mic.wav", "", 0, 0)
record("close recsound", "", 0, 0)
TextBoxInput.Enabled = True
ButtonStartDelay.Enabled = True
ButtonStartDelay.Text = "Start Delay"
End Sub

Private Sub TimerDelay_Tick(sender As Object, e As EventArgs) Handles TimerDelay.Tick


If (ProgressBar1.Value = ProgressBar1.Maximum) Then
TimerDelay.Stop()
Else
ProgressBar1.Value += 1
End If
End Sub

Private Shared Sub AppendLine(destination As TextBox, line As String)
destination.Lines = destination.Lines.Concat({line}).ToArray()
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
OpenFileDialog1.Title = "Please select a subtitle file"
OpenFileDialog1.FileName = ""
' OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.Filter = "Subtitle Files|*.srt"

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim content As String = File.ReadAllText(OpenFileDialog1.FileName, Encoding.UTF8)
TextBoxInput.Text = content
End If
TextBoxInput.Lines = TextBoxInput.Lines.Where(Function(line) line <> String.Empty).ToArray()

Dim Term As String = " -->"
Dim lines() As String = TextBoxInput.Lines
For x As Integer = 0 To lines.GetUpperBound(0)
If lines(x).Contains(Term) Then
lines(x) = lines(x).Substring(0, lines(x).IndexOf(Term))
End If
Next
TextBoxInput.Lines = lines
End Sub
End Class

  • hamsteg
  • Registratie: Mei 2003
  • Laatst online: 17:12

hamsteg

Species 5618

Even in < code > zetten:
C++:
1
2
3
4
5
6
7
8
9
10
Imports System
Imports System.Globalization
Imports System.Speech.Synthesis
Imports System.Threading
Imports System.Threading.Thread
Imports System.Speech.AudioFormat
Imports System.IO
Imports System.Media
Imports System.Text.RegularExpressions
Imports System.Text

Niet quoten, zorgvuldige reacties volgens de regels worden zo weggewerkt: *knip*, reactie op geknipte reactie.


  • W1ck1e
  • Registratie: Februari 2008
  • Laatst online: 23:05
@Richard1234
Een eerste tweede reactie: wat is de context ?
Hardware, software, doel, platform, soort van content ?

[ Voor 6% gewijzigd door W1ck1e op 08-09-2026 12:41 ]


  • dixet
  • Registratie: Februari 2010
  • Laatst online: 22:15
En zorg voor inspringing van je code als je wilt dat we het hier kunnen lezen en begrijpen.

Je zegt "Maar mij [sic] programma stopt er te voeg mee." Geeft hij een foutmelding? Stopt het na een x aantal regels? En wat voor taal gebruik je? VB? C++?

Wat meer context en informatie helpt ons jou te helpen

  • Richard1234
  • Registratie: September 2026
  • Laatst online: 19:18
visual basic.net

  • Marber
  • Registratie: Juni 2014
  • Laatst online: 15:39
Controleer SpeakAsync. Ik vermoed dat het daarin zit.

Maar probeer je code volgende keer iets beter weer te geven hier en je vraag iets duidelijker te stellen.

  • Richard1234
  • Registratie: September 2026
  • Laatst online: 19:18
Ik weet al hoe het kom.
De ondertitel staat te dicht achter elkaar.

  • Richard1234
  • Registratie: September 2026
  • Laatst online: 19:18
okee is goed.
Pagina: 1