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
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