ho creato un programma che fa parlare il pc leggendo quello che c'è scritto in una textbox e registra il parlato in un file audio il codice è questo:
- Codice: Seleziona tutto
Imports System.Speech.Synthesis
Imports System.Runtime.InteropServices
Public Class Form1
Private speaker As New SpeechSynthesizer
Private recording As Boolean = False
Private file As String
Private salva As New SaveFileDialog
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim CercaVoci() As String = CercaVoci_Nel_SintetizzatoreVocale()
For Each Str As String In CercaVoci 'Elenca tutte le voci
ComboBox1.Items.Add(Str.ToString)
Next
salva.Filter = "audio wave(*.wav)|*.wav"
End Sub
<DllImport("winmm.dll")>
Private Shared Function mciSendString(ByVal command As String, ByVal buffer As String, ByVal bufferSize As Integer, ByVal hwndCallBack As IntPtr) As Integer
End Function
Private Sub speakButton_Click(sender As Object, e As EventArgs) Handles speakButton.Click
If recording = False Then
If file = "" Then
MsgBox("Imposta la directory di destinazione", MsgBoxStyle.Critical) : Exit Sub
End If
mciSendString("open new Type waveaudio alias recsound", "", 0, 0)
mciSendString("record recsound", "", 0, 0)
recording = True
speaker.Rate = Convert.ToInt32(speedUpDown.Value)
speaker.Volume = Convert.ToInt32(volumeUpDown.Value)
speaker.SpeakAsync(speakTextBox.Text)
playButton.Enabled = False
speakButton.Text = "Stop"
Else
mciSendString("save recsound " & file, "", 0, 0)
mciSendString("close recsound", "", 0, 0)
recording = False
playButton.Enabled = True
speakButton.Text = "Speak"
End If
End Sub
Private Sub directoryButton_Click(sender As Object, e As EventArgs) Handles directoryButton.Click
If salva.ShowDialog = Windows.Forms.DialogResult.OK Then
file = salva.FileName
End If
End Sub
Function CercaVoci_Nel_SintetizzatoreVocale() As String()
Dim oSpeech As New System.Speech.Synthesis.SpeechSynthesizer()
Dim installedVoices As System.Collections.ObjectModel.
ReadOnlyCollection(Of System.Speech.Synthesis.InstalledVoice) _
= oSpeech.GetInstalledVoices
Dim names(installedVoices.Count - 1) As String
For i As Integer = 0 To installedVoices.Count - 1
names(i) = installedVoices(i).VoiceInfo.Name
Next
Return names
End Function
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
speaker.SelectVoice(ComboBox1.Text)
End Sub
End Class
il problema è che registra dal microfono quindi si sentono anche i rumori di sottofondo, io vorrei che registra l'audio del pc.