egilchri
egilchri

Reputation: 761

Python Text to Speech on Mac Pronouncing Danish Words Wrong

I have the following program that is trying to pronounce a line of Danish text. I can't figure out why it is pronouncing it wrong. It should sound like "po so mo fo po", but it doesn't sound at all like that. It sounds more like "p n s n m n f n p n". I am using the Danish voice "Magnus" so it should know how to pronounce these. Also, when I use OSX Voice Over to pronounce the words it sounds right.

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

from  AppKit import NSSpeechSynthesizer
import time
import sys

nssp = NSSpeechSynthesizer
ve = nssp.alloc().init()

from_voice = "com.apple.speech.synthesis.voice.magnus.premium"

line = "på så må få på"

ve.setVoice_(from_voice)
ve.startSpeakingString_(line)
time.sleep(1)

while ve.isSpeaking():
   time.sleep(1)

Upvotes: 1

Views: 197

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121366

You need to pass in a unicode object, not a UTF-8 bytestring:

ve.startSpeakingString_(line.decode('utf8'))

You could define the line value as a Unicode literal instead of decoding:

line = u"på så må få på"

Upvotes: 2

Related Questions